Search in sources :

Example 1 with StylesTable

use of org.apache.poi.xssf.model.StylesTable in project poi by apache.

the class XSSFReader method getStylesTable.

/**
     * 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());
    if (parts.size() == 0)
        return null;
    // Create the Styles Table, and associate the Themes if present
    StylesTable styles = new StylesTable(parts.get(0));
    parts = pkg.getPartsByContentType(XSSFRelation.THEME.getContentType());
    if (parts.size() != 0) {
        styles.setTheme(new ThemesTable(parts.get(0)));
    }
    return styles;
}
Also used : ThemesTable(org.apache.poi.xssf.model.ThemesTable) StylesTable(org.apache.poi.xssf.model.StylesTable) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 2 with StylesTable

use of org.apache.poi.xssf.model.StylesTable in project poi by apache.

the class XSSFConditionalFormattingRule method getDxf.

/*package*/
CTDxf getDxf(boolean create) {
    StylesTable styles = _sh.getWorkbook().getStylesSource();
    CTDxf dxf = null;
    if (styles._getDXfsSize() > 0 && _cfRule.isSetDxfId()) {
        int dxfId = (int) _cfRule.getDxfId();
        dxf = styles.getDxfAt(dxfId);
    }
    if (create && dxf == null) {
        dxf = CTDxf.Factory.newInstance();
        int dxfId = styles.putDxf(dxf);
        _cfRule.setDxfId(dxfId - 1);
    }
    return dxf;
}
Also used : StylesTable(org.apache.poi.xssf.model.StylesTable)

Example 3 with StylesTable

use of org.apache.poi.xssf.model.StylesTable in project poi by apache.

the class XLSX2CSV method process.

/**
     * Initiates the processing of the XLS workbook file to CSV.
     *
     * @throws IOException If reading the data from the package fails.
     * @throws SAXException if parsing the XML data fails.
     */
public void process() throws IOException, OpenXML4JException, 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();
        this.output.println();
        this.output.println(sheetName + " [index=" + index + "]:");
        processSheet(styles, strings, new SheetToCSV(), stream);
        stream.close();
        ++index;
    }
}
Also used : InputStream(java.io.InputStream) StylesTable(org.apache.poi.xssf.model.StylesTable)

Example 4 with StylesTable

use of org.apache.poi.xssf.model.StylesTable in project poi by apache.

the class XSSFRow method setRowStyle.

/**
     * Applies a whole-row cell styling to the row.
     * If the value is null then the style information is removed,
     *  causing the cell to used the default workbook style.
     */
@Override
public void setRowStyle(CellStyle style) {
    if (style == null) {
        if (_row.isSetS()) {
            _row.unsetS();
            _row.unsetCustomFormat();
        }
    } else {
        StylesTable styleSource = getSheet().getWorkbook().getStylesSource();
        XSSFCellStyle xStyle = (XSSFCellStyle) style;
        xStyle.verifyBelongsToStylesSource(styleSource);
        long idx = styleSource.putStyle(xStyle);
        _row.setS(idx);
        _row.setCustomFormat(true);
    }
}
Also used : StylesTable(org.apache.poi.xssf.model.StylesTable)

Example 5 with StylesTable

use of org.apache.poi.xssf.model.StylesTable in project poi by apache.

the class TestXSSFCellStyle method setUp.

@Before
public void setUp() {
    stylesTable = new StylesTable();
    ctStylesheet = stylesTable.getCTStylesheet();
    ctBorderA = CTBorder.Factory.newInstance();
    XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA);
    long borderId = stylesTable.putBorder(borderA);
    assertEquals(1, borderId);
    XSSFCellBorder borderB = new XSSFCellBorder();
    assertEquals(1, stylesTable.putBorder(borderB));
    ctFill = CTFill.Factory.newInstance();
    XSSFCellFill fill = new XSSFCellFill(ctFill, null);
    long fillId = stylesTable.putFill(fill);
    assertEquals(2, fillId);
    ctFont = CTFont.Factory.newInstance();
    XSSFFont font = new XSSFFont(ctFont);
    long fontId = stylesTable.putFont(font);
    assertEquals(1, fontId);
    cellStyleXf = ctStylesheet.addNewCellStyleXfs().addNewXf();
    cellStyleXf.setBorderId(1);
    cellStyleXf.setFillId(1);
    cellStyleXf.setFontId(1);
    cellXfs = ctStylesheet.addNewCellXfs();
    cellXf = cellXfs.addNewXf();
    cellXf.setXfId(1);
    cellXf.setBorderId(1);
    cellXf.setFillId(1);
    cellXf.setFontId(1);
    stylesTable.putCellStyleXf(cellStyleXf);
    stylesTable.putCellXf(cellXf);
    cellStyle = new XSSFCellStyle(1, 1, stylesTable, null);
    assertNotNull(stylesTable.getFillAt(1).getCTFill().getPatternFill());
    assertEquals(STPatternType.INT_DARK_GRAY, stylesTable.getFillAt(1).getCTFill().getPatternFill().getPatternType().intValue());
}
Also used : StylesTable(org.apache.poi.xssf.model.StylesTable) XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill) XSSFCellBorder(org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder) Before(org.junit.Before)

Aggregations

StylesTable (org.apache.poi.xssf.model.StylesTable)20 Test (org.junit.Test)8 InputStream (java.io.InputStream)4 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)4 ReadOnlySharedStringsTable (org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable)3 XSSFReader (org.apache.poi.xssf.eventusermodel.XSSFReader)3 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)2 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)2 CommentsTable (org.apache.poi.xssf.model.CommentsTable)2 ThemesTable (org.apache.poi.xssf.model.ThemesTable)2 XmlException (org.apache.xmlbeans.XmlException)2 CTWorksheet (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet)2 CTXf (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)1 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)1 POIXMLException (org.apache.poi.POIXMLException)1