Package org.apache.poi.xssf.model

Examples of org.apache.poi.xssf.model.StylesTable


     * Avoid ArrayIndexOutOfBoundsException  when creating cell style
     * in a workbook that has an empty xf table.
     */
    public void testBug52348() {
        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("52348.xlsx");
        StylesTable st = workbook.getStylesSource();
        assertEquals(0, st._getStyleXfsSize());
       
        XSSFCellStyle style = workbook.createCellStyle(); // no exception at this point
        assertNull(style.getStyleXf());

        assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(workbook));
View Full Code Here


     * Avoid ArrayIndexOutOfBoundsException  when getting cell style
     * in a workbook that has an empty xf table.
     */
    public void testBug55650() {
        XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("52348.xlsx");
        StylesTable st = workbook.getStylesSource();
        assertEquals(0, st._getStyleXfsSize());

        // no exception at this point
        XSSFCellStyle style = workbook.getSheetAt(0).getRow(0).getCell(0).getCellStyle();
        assertNull(style.getStyleXf());

View Full Code Here

     * Opens up the Styles Table, parses it, and
     *  returns a handy object for working with cell styles
     */
    public StylesTable getStylesTable() throws IOException, InvalidFormatException {
        ArrayList<PackagePart> parts = pkg.getPartsByContentType( XSSFRelation.STYLES.getContentType());
        return parts.size() == 0 ? null : new StylesTable(parts.get(0), null);
    }
View Full Code Here

   
    public void testSetDefaultColumnStyle() {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet();
        CTWorksheet ctWorksheet = sheet.getCTWorksheet();
      StylesTable stylesTable = workbook.getStylesSource();
      XSSFFont font = new XSSFFont();
      font.setFontName("Cambria");
      stylesTable.putFont(font);
      CTXf cellStyleXf = CTXf.Factory.newInstance();
      cellStyleXf.setFontId(1);
      cellStyleXf.setFillId(0);
      cellStyleXf.setBorderId(0);
      cellStyleXf.setNumFmtId(0);
      stylesTable.putCellStyleXf(cellStyleXf);
      CTXf cellXf = CTXf.Factory.newInstance();
      cellXf.setXfId(1);
      stylesTable.putCellXf(cellXf);
      XSSFCellStyle cellStyle = new XSSFCellStyle(1, 1, stylesTable);
      assertEquals(1, cellStyle.getFontIndex());
     
      sheet.setDefaultColumnStyle((short) 3, cellStyle);
      assertEquals(1, ctWorksheet.getColsArray(0).getColArray(0).getStyle());
View Full Code Here

        assertNotNull(col);
        assertNotNull(columnHelper.getColumn(3, false));
        columnHelper.setColDefaultStyle(3, 2);
        assertEquals(2, columnHelper.getColDefaultStyle(3));
        assertEquals(-1, columnHelper.getColDefaultStyle(4));
        StylesTable stylesTable = workbook.getStylesSource();
        CTXf cellXf = CTXf.Factory.newInstance();
        cellXf.setFontId(0);
        cellXf.setFillId(0);
        cellXf.setBorderId(0);
        cellXf.setNumFmtId(0);
        cellXf.setXfId(0);
        stylesTable.putCellXf(cellXf);
        CTCol col_2 = ctWorksheet.getColsArray(0).addNewCol();
        col_2.setMin(10);
        col_2.setMax(12);
        col_2.setStyle(1);
        assertEquals(1, columnHelper.getColDefaultStyle(11));
View Full Code Here

    //get default style
    CellStyle cellStyleAt = workbook.getCellStyleAt(i);
    assertNotNull(cellStyleAt);
   
    //get custom style
    StylesTable styleSource = workbook.getStylesSource();
    XSSFCellStyle customStyle = new XSSFCellStyle(styleSource);
    XSSFFont font = new XSSFFont();
    font.setFontName("Verdana");
    customStyle.setFont(font);
    int x = styleSource.putStyle(customStyle);
    cellStyleAt = workbook.getCellStyleAt((short)x);
    assertNotNull(cellStyleAt);   
  }
View Full Code Here

    assertNotNull(cellStyleAt);   
  }
 
  public void testGetFontAt(){
     XSSFWorkbook workbook = new XSSFWorkbook();
    StylesTable styleSource = workbook.getStylesSource();
    short i = 0;
    //get default font
    Font fontAt = workbook.getFontAt(i);
    assertNotNull(fontAt);
   
    //get customized font
    XSSFFont customFont = new XSSFFont();
    customFont.setItalic(true);
    int x = styleSource.putFont(customFont);
    fontAt = workbook.getFontAt((short)x);
    assertNotNull(fontAt);
  }
View Full Code Here

  }
 
  public void testStyles() {
    XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
   
    StylesTable ss = workbook.getStylesSource();
    assertNotNull(ss);
    StylesTable st = ss;
   
    // Has 8 number formats
    assertEquals(8, st._getNumberFormatSize());
    // Has 2 fonts
    assertEquals(2, st.getFonts().size());
    // Has 2 fills
    assertEquals(2, st.getFills().size());
    // Has 1 border
    assertEquals(1, st.getBorders().size());
   
    // Add two more styles
    assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 8,
        st.putNumberFormat("testFORMAT"));
    assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 8,
        st.putNumberFormat("testFORMAT"));
    assertEquals(StylesTable.FIRST_CUSTOM_STYLE_ID + 9,
        st.putNumberFormat("testFORMAT2"));
    assertEquals(10, st._getNumberFormatSize());
   
   
    // Save, load back in again, and check
    workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
   
    ss = workbook.getStylesSource();
    assertNotNull(ss);

    assertEquals(10, st._getNumberFormatSize());
    assertEquals(2, st.getFonts().size());
    assertEquals(2, st.getFills().size());
    assertEquals(1, st.getBorders().size());
  }
View Full Code Here

  private XSSFCellStyle cellStyle;
  private CTStylesheet ctStylesheet;

  @Override
  protected void setUp() {
    stylesTable = new StylesTable();
   
    ctStylesheet = stylesTable.getCTStylesheet();
   
    ctBorderA = CTBorder.Factory.newInstance();
    XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA);
View Full Code Here

 

  public void testGetFillForegroundColor() {

        XSSFWorkbook wb = new XSSFWorkbook();
        StylesTable styles = wb.getStylesSource();
        assertEquals(1, wb.getNumCellStyles());
        assertEquals(2, styles.getFills().size());

        XSSFCellStyle defaultStyle = wb.getCellStyleAt((short)0);
        assertEquals(IndexedColors.AUTOMATIC.getIndex(), defaultStyle.getFillForegroundColor());
        assertEquals(null, defaultStyle.getFillForegroundXSSFColor());
        assertEquals(CellStyle.NO_FILL, defaultStyle.getFillPattern());

        XSSFCellStyle customStyle = wb.createCellStyle();

        customStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
        assertEquals(CellStyle.SOLID_FOREGROUND, customStyle.getFillPattern());
        assertEquals(3, styles.getFills().size());

        customStyle.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
        assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), customStyle.getFillForegroundColor());
        assertEquals(4, styles.getFills().size());

        for (int i = 0; i < 3; i++) {
            XSSFCellStyle style = wb.createCellStyle();

            style.setFillPattern(CellStyle.SOLID_FOREGROUND);
            assertEquals(CellStyle.SOLID_FOREGROUND, style.getFillPattern());
            assertEquals(4, styles.getFills().size());

            style.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
            assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), style.getFillForegroundColor());
            assertEquals(4, styles.getFills().size());
        }
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.xssf.model.StylesTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.