Search in sources :

Example 1 with IndexedColorMap

use of org.apache.poi.xssf.usermodel.IndexedColorMap in project poi by apache.

the class StylesTable method readFrom.

/**
     * Read this shared styles table from an XML file.
     *
     * @param is The input stream containing the XML document.
     * @throws IOException if an error occurs while reading.
     */
public void readFrom(InputStream is) throws IOException {
    try {
        doc = StyleSheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        CTStylesheet styleSheet = doc.getStyleSheet();
        // Grab all the different bits we care about
        // keep this first, as some constructors below want it
        IndexedColorMap customColors = CustomIndexedColorMap.fromColors(styleSheet.getColors());
        if (customColors != null)
            indexedColors = customColors;
        CTNumFmts ctfmts = styleSheet.getNumFmts();
        if (ctfmts != null) {
            for (CTNumFmt nfmt : ctfmts.getNumFmtArray()) {
                short formatId = (short) nfmt.getNumFmtId();
                numberFormats.put(formatId, nfmt.getFormatCode());
            }
        }
        CTFonts ctfonts = styleSheet.getFonts();
        if (ctfonts != null) {
            int idx = 0;
            for (CTFont font : ctfonts.getFontArray()) {
                // Create the font and save it. Themes Table supplied later
                XSSFFont f = new XSSFFont(font, idx, indexedColors);
                fonts.add(f);
                idx++;
            }
        }
        CTFills ctfills = styleSheet.getFills();
        if (ctfills != null) {
            for (CTFill fill : ctfills.getFillArray()) {
                fills.add(new XSSFCellFill(fill, indexedColors));
            }
        }
        CTBorders ctborders = styleSheet.getBorders();
        if (ctborders != null) {
            for (CTBorder border : ctborders.getBorderArray()) {
                borders.add(new XSSFCellBorder(border, indexedColors));
            }
        }
        CTCellXfs cellXfs = styleSheet.getCellXfs();
        if (cellXfs != null)
            xfs.addAll(Arrays.asList(cellXfs.getXfArray()));
        CTCellStyleXfs cellStyleXfs = styleSheet.getCellStyleXfs();
        if (cellStyleXfs != null)
            styleXfs.addAll(Arrays.asList(cellStyleXfs.getXfArray()));
        CTDxfs styleDxfs = styleSheet.getDxfs();
        if (styleDxfs != null)
            dxfs.addAll(Arrays.asList(styleDxfs.getDxfArray()));
        CTTableStyles ctTableStyles = styleSheet.getTableStyles();
        if (ctTableStyles != null) {
            int idx = 0;
            for (CTTableStyle style : Arrays.asList(ctTableStyles.getTableStyleArray())) {
                tableStyles.put(style.getName(), new XSSFTableStyle(idx, styleDxfs, style, indexedColors));
                idx++;
            }
        }
    } catch (XmlException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}
Also used : DefaultIndexedColorMap(org.apache.poi.xssf.usermodel.DefaultIndexedColorMap) IndexedColorMap(org.apache.poi.xssf.usermodel.IndexedColorMap) CustomIndexedColorMap(org.apache.poi.xssf.usermodel.CustomIndexedColorMap) XSSFTableStyle(org.apache.poi.xssf.usermodel.XSSFTableStyle) IOException(java.io.IOException) XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill) XmlException(org.apache.xmlbeans.XmlException) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFCellBorder(org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)

Aggregations

IOException (java.io.IOException)1 CustomIndexedColorMap (org.apache.poi.xssf.usermodel.CustomIndexedColorMap)1 DefaultIndexedColorMap (org.apache.poi.xssf.usermodel.DefaultIndexedColorMap)1 IndexedColorMap (org.apache.poi.xssf.usermodel.IndexedColorMap)1 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)1 XSSFTableStyle (org.apache.poi.xssf.usermodel.XSSFTableStyle)1 XSSFCellBorder (org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)1 XSSFCellFill (org.apache.poi.xssf.usermodel.extensions.XSSFCellFill)1 XmlException (org.apache.xmlbeans.XmlException)1