Package org.apache.poi.xssf.model

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


    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, null);
        assertEquals(1, cellStyle.getFontIndex());

        sheet.setDefaultColumnStyle(3, cellStyle);
        assertEquals(1, ctWorksheet.getColsArray(0).getColArray(0).getStyle());
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

    public void process()
            throws IOException, OpenXML4JException, ParserConfigurationException, SAXException {

        ReadonlySharedStringsTable strings = new ReadonlySharedStringsTable(this.xlsxPackage);
        XSSFReader xssfReader = new XSSFReader(this.xlsxPackage);
        StylesTable styles = xssfReader.getStylesTable();
        XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
        int index = 0;
        while (iter.hasNext()) {
            InputStream stream = iter.next();
            String sheetName = iter.getSheetName();
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

    //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

       OPCPackage container = extractor.getPackage();
      
       ReadOnlySharedStringsTable strings;
       XSSFReader.SheetIterator iter;
       XSSFReader xssfReader;
       StylesTable styles;
       try {
          xssfReader = new XSSFReader(container);
          styles = xssfReader.getStylesTable();
          iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
          strings = new ReadOnlySharedStringsTable(container);
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

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.