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());
}
}
Aggregations