Search in sources :

Example 1 with CTSst

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst in project poi by apache.

the class SharedStringsTable method readFrom.

/**
     * Read this shared strings 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 {
        int cnt = 0;
        _sstDoc = SstDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        CTSst sst = _sstDoc.getSst();
        count = (int) sst.getCount();
        uniqueCount = (int) sst.getUniqueCount();
        for (CTRst st : sst.getSiArray()) {
            stmap.put(getKey(st), cnt);
            strings.add(st);
            cnt++;
        }
    } catch (XmlException e) {
        throw new IOException("unable to parse shared strings table", e);
    }
}
Also used : CTSst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst) CTRst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst) XmlException(org.apache.xmlbeans.XmlException) IOException(java.io.IOException)

Example 2 with CTSst

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst in project poi by apache.

the class SharedStringsTable method writeTo.

/**
     * Write this table out as XML.
     * 
     * @param out The stream to write to.
     * @throws IOException if an error occurs while writing.
     */
public void writeTo(OutputStream out) throws IOException {
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    // the following two lines turn off writing CDATA
    // see Bugzilla 48936
    xmlOptions.setSaveCDataLengthThreshold(1000000);
    xmlOptions.setSaveCDataEntityCountThreshold(-1);
    //re-create the sst table every time saving a workbook
    CTSst sst = _sstDoc.getSst();
    sst.setCount(count);
    sst.setUniqueCount(uniqueCount);
    _sstDoc.save(out, xmlOptions);
}
Also used : CTSst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst) XmlOptions(org.apache.xmlbeans.XmlOptions)

Aggregations

CTSst (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst)2 IOException (java.io.IOException)1 XmlException (org.apache.xmlbeans.XmlException)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1 CTRst (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst)1