Search in sources :

Example 1 with ThemesTable

use of org.apache.poi.xssf.model.ThemesTable 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 ThemesTable

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

the class XSSFRichTextString method getFontAtIndex.

/**
     * Return a copy of the font in use at a particular index.
     *
     * @param index         The index.
     * @return              A copy of the  font that's currently being applied at that
     *                      index or null if no font is being applied or the
     *                      index is out of range.
     */
public XSSFFont getFontAtIndex(int index) {
    final ThemesTable themes = getThemesTable();
    int pos = 0;
    //noinspection deprecation - for performance reasons!
    for (CTRElt r : st.getRArray()) {
        final int length = r.getT().length();
        if (index >= pos && index < pos + length) {
            XSSFFont fnt = new XSSFFont(toCTFont(r.getRPr()));
            fnt.setThemesTable(themes);
            return fnt;
        }
        pos += length;
    }
    return null;
}
Also used : ThemesTable(org.apache.poi.xssf.model.ThemesTable) CTRElt(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt)

Example 3 with ThemesTable

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

the class XSSFWorkbook method onDocumentRead.

@Override
protected void onDocumentRead() throws IOException {
    try {
        WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
        this.workbook = doc.getWorkbook();
        ThemesTable theme = null;
        Map<String, XSSFSheet> shIdMap = new HashMap<String, XSSFSheet>();
        Map<String, ExternalLinksTable> elIdMap = new HashMap<String, ExternalLinksTable>();
        for (RelationPart rp : getRelationParts()) {
            POIXMLDocumentPart p = rp.getDocumentPart();
            if (p instanceof SharedStringsTable) {
                sharedStringSource = (SharedStringsTable) p;
            } else if (p instanceof StylesTable) {
                stylesSource = (StylesTable) p;
            } else if (p instanceof ThemesTable) {
                theme = (ThemesTable) p;
            } else if (p instanceof CalculationChain) {
                calcChain = (CalculationChain) p;
            } else if (p instanceof MapInfo) {
                mapInfo = (MapInfo) p;
            } else if (p instanceof XSSFSheet) {
                shIdMap.put(rp.getRelationship().getId(), (XSSFSheet) p);
            } else if (p instanceof ExternalLinksTable) {
                elIdMap.put(rp.getRelationship().getId(), (ExternalLinksTable) p);
            }
        }
        boolean packageReadOnly = (getPackage().getPackageAccess() == PackageAccess.READ);
        if (stylesSource == null) {
            // Create Styles if it is missing
            if (packageReadOnly) {
                stylesSource = new StylesTable();
            } else {
                stylesSource = (StylesTable) createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance());
            }
        }
        stylesSource.setWorkbook(this);
        stylesSource.setTheme(theme);
        if (sharedStringSource == null) {
            // Create SST if it is missing
            if (packageReadOnly) {
                sharedStringSource = new SharedStringsTable();
            } else {
                sharedStringSource = (SharedStringsTable) createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance());
            }
        }
        // Load individual sheets. The order of sheets is defined by the order
        //  of CTSheet elements in the workbook
        sheets = new ArrayList<XSSFSheet>(shIdMap.size());
        for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
            parseSheet(shIdMap, ctSheet);
        }
        // Load the external links tables. Their order is defined by the order 
        //  of CTExternalReference elements in the workbook
        externalLinks = new ArrayList<ExternalLinksTable>(elIdMap.size());
        if (this.workbook.isSetExternalReferences()) {
            for (CTExternalReference er : this.workbook.getExternalReferences().getExternalReferenceArray()) {
                ExternalLinksTable el = elIdMap.get(er.getId());
                if (el == null) {
                    logger.log(POILogger.WARN, "ExternalLinksTable with r:id " + er.getId() + " was defined, but didn't exist in package, skipping");
                    continue;
                }
                externalLinks.add(el);
            }
        }
        // Process the named ranges
        reprocessNamedRanges();
    } catch (XmlException e) {
        throw new POIXMLException(e);
    }
}
Also used : WorkbookDocument(org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument) ThemesTable(org.apache.poi.xssf.model.ThemesTable) HashMap(java.util.HashMap) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) CTExternalReference(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExternalReference) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) StylesTable(org.apache.poi.xssf.model.StylesTable) POIXMLException(org.apache.poi.POIXMLException) CalculationChain(org.apache.poi.xssf.model.CalculationChain) SharedStringsTable(org.apache.poi.xssf.model.SharedStringsTable) CTSheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet) XmlException(org.apache.xmlbeans.XmlException) MapInfo(org.apache.poi.xssf.model.MapInfo) ExternalLinksTable(org.apache.poi.xssf.model.ExternalLinksTable)

Aggregations

ThemesTable (org.apache.poi.xssf.model.ThemesTable)3 StylesTable (org.apache.poi.xssf.model.StylesTable)2 HashMap (java.util.HashMap)1 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)1 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)1 POIXMLException (org.apache.poi.POIXMLException)1 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)1 CalculationChain (org.apache.poi.xssf.model.CalculationChain)1 ExternalLinksTable (org.apache.poi.xssf.model.ExternalLinksTable)1 MapInfo (org.apache.poi.xssf.model.MapInfo)1 SharedStringsTable (org.apache.poi.xssf.model.SharedStringsTable)1 XmlException (org.apache.xmlbeans.XmlException)1 CTExternalReference (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTExternalReference)1 CTRElt (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt)1 CTSheet (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet)1 WorkbookDocument (org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument)1