public class ReadOnlySharedStringsTable extends org.xml.sax.helpers.DefaultHandler implements SharedStrings
This is a lightweight way to process the Shared Strings table. Most of the text cells will reference something from in here.
Note that each SI entry can have multiple T elements, if the string is made up of bits with different formatting.
Example input:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="2" uniqueCount="2">
<si>
<r>
<rPr>
<b />
<sz val="11" />
<color theme="1" />
<rFont val="Calibri" />
<family val="2" />
<scheme val="minor" />
</rPr>
<t>This:</t>
</r>
<r>
<rPr>
<sz val="11" />
<color theme="1" />
<rFont val="Calibri" />
<family val="2" />
<scheme val="minor" />
</rPr>
<t xml:space="preserve">Causes Problems</t>
</r>
</si>
<si>
<t>This does not</t>
</si>
</sst>
| Modifier and Type | Field and Description |
|---|---|
protected int |
count
An integer representing the total count of strings in the workbook.
|
protected boolean |
includePhoneticRuns |
protected int |
uniqueCount
An integer representing the total count of unique strings in the Shared String Table.
|
| Constructor and Description |
|---|
ReadOnlySharedStringsTable(java.io.InputStream stream) |
ReadOnlySharedStringsTable(java.io.InputStream stream,
boolean includePhoneticRuns) |
ReadOnlySharedStringsTable(OPCPackage pkg)
Calls {
ReadOnlySharedStringsTable(OPCPackage, boolean)} with
a value of true for including phonetic runs |
ReadOnlySharedStringsTable(OPCPackage pkg,
boolean includePhoneticRuns) |
ReadOnlySharedStringsTable(PackagePart part)
Like POIXMLDocumentPart constructor
Calls
ReadOnlySharedStringsTable(PackagePart, boolean), with a
value of true to include phonetic runs. |
ReadOnlySharedStringsTable(PackagePart part,
boolean includePhoneticRuns) |
| Modifier and Type | Method and Description |
|---|---|
void |
characters(char[] ch,
int start,
int length)
Captures characters only if a t(ext) element is open.
|
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String name) |
int |
getCount()
Return an integer representing the total count of strings in the workbook.
|
RichTextString |
getItemAt(int idx)
Return a string item by index
|
int |
getUniqueCount()
Returns an integer representing the total count of unique strings in the Shared String Table.
|
void |
readFrom(java.io.InputStream is)
Read this shared strings table from an XML file.
|
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String name,
org.xml.sax.Attributes attributes) |
protected final boolean includePhoneticRuns
protected int count
protected int uniqueCount
public ReadOnlySharedStringsTable(OPCPackage pkg) throws java.io.IOException, org.xml.sax.SAXException
ReadOnlySharedStringsTable(OPCPackage, boolean)} with
a value of true for including phonetic runspkg - The OPCPackage to use as basis for the shared-strings table.java.io.IOException - If reading the data from the package fails.org.xml.sax.SAXException - if parsing the XML data fails.public ReadOnlySharedStringsTable(OPCPackage pkg, boolean includePhoneticRuns) throws java.io.IOException, org.xml.sax.SAXException
pkg - The OPCPackage to use as basis for the shared-strings table.includePhoneticRuns - whether or not to concatenate phoneticRuns onto the shared stringjava.io.IOException - If reading the data from the package fails.org.xml.sax.SAXException - if parsing the XML data fails.public ReadOnlySharedStringsTable(PackagePart part) throws java.io.IOException, org.xml.sax.SAXException
ReadOnlySharedStringsTable(PackagePart, boolean), with a
value of true to include phonetic runs.java.io.IOExceptionorg.xml.sax.SAXExceptionpublic ReadOnlySharedStringsTable(PackagePart part, boolean includePhoneticRuns) throws java.io.IOException, org.xml.sax.SAXException
java.io.IOExceptionorg.xml.sax.SAXExceptionpublic ReadOnlySharedStringsTable(java.io.InputStream stream)
throws java.io.IOException,
org.xml.sax.SAXException
java.io.IOExceptionorg.xml.sax.SAXExceptionpublic ReadOnlySharedStringsTable(java.io.InputStream stream,
boolean includePhoneticRuns)
throws java.io.IOException,
org.xml.sax.SAXException
java.io.IOExceptionorg.xml.sax.SAXExceptionpublic void readFrom(java.io.InputStream is)
throws java.io.IOException,
org.xml.sax.SAXException
is - The input stream containing the XML document.java.io.IOException - if an error occurs while reading.org.xml.sax.SAXException - if parsing the XML data fails.public int getCount()
getCount in interface SharedStringspublic int getUniqueCount()
getUniqueCount in interface SharedStringspublic RichTextString getItemAt(int idx)
SharedStringsgetItemAt in interface SharedStringsidx - index of item to return.public void startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String name,
org.xml.sax.Attributes attributes)
throws org.xml.sax.SAXException
startElement in interface org.xml.sax.ContentHandlerstartElement in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXExceptionpublic void endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String name)
throws org.xml.sax.SAXException
endElement in interface org.xml.sax.ContentHandlerendElement in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXExceptionpublic void characters(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
characters in interface org.xml.sax.ContentHandlercharacters in class org.xml.sax.helpers.DefaultHandlerorg.xml.sax.SAXExceptionCopyright 2022 The Apache Software Foundation or its licensors, as applicable.