Class ReadOnlySharedStringsTable
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable
- All Implemented Interfaces:
SharedStrings
,ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
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>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
An integer representing the total count of strings in the workbook.protected final boolean
protected int
An integer representing the total count of unique strings in the Shared String Table. -
Constructor Summary
ConstructorsConstructorDescriptionCalls {ReadOnlySharedStringsTable(OPCPackage, boolean)
} with a value oftrue
for including phonetic runsReadOnlySharedStringsTable
(OPCPackage pkg, boolean includePhoneticRuns) Like POIXMLDocumentPart constructor CallsReadOnlySharedStringsTable(PackagePart, boolean)
, with a value oftrue
to include phonetic runs.ReadOnlySharedStringsTable
(PackagePart part, boolean includePhoneticRuns) Like POIXMLDocumentPart constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
characters
(char[] ch, int start, int length) Captures characters only if a t(ext) element is open.void
endElement
(String uri, String localName, String name) int
getCount()
Return an integer representing the total count of strings in the workbook.getEntryAt
(int idx) Deprecated.getItemAt
(int idx) Return a string item by indexgetItems()
Deprecated.usegetItemAt
insteadint
Returns an integer representing the total count of unique strings in the Shared String Table.void
readFrom
(InputStream is) Read this shared strings table from an XML file.void
startElement
(String uri, String localName, String name, Attributes attributes) Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
includePhoneticRuns
protected final boolean includePhoneticRuns -
count
protected int countAn integer representing the total count of strings in the workbook. This count does not include any numbers, it counts only the total of text strings in the workbook. -
uniqueCount
protected int uniqueCountAn integer representing the total count of unique strings in the Shared String Table. A string is unique even if it is a copy of another string, but has different formatting applied at the character level.
-
-
Constructor Details
-
ReadOnlySharedStringsTable
Calls {ReadOnlySharedStringsTable(OPCPackage, boolean)
} with a value oftrue
for including phonetic runs- Parameters:
pkg
- TheOPCPackage
to use as basis for the shared-strings table.- Throws:
IOException
- If reading the data from the package fails.SAXException
- if parsing the XML data fails.
-
ReadOnlySharedStringsTable
public ReadOnlySharedStringsTable(OPCPackage pkg, boolean includePhoneticRuns) throws IOException, SAXException - Parameters:
pkg
- TheOPCPackage
to use as basis for the shared-strings table.includePhoneticRuns
- whether or not to concatenate phoneticRuns onto the shared string- Throws:
IOException
- If reading the data from the package fails.SAXException
- if parsing the XML data fails.- Since:
- POI 3.14-Beta3
-
ReadOnlySharedStringsTable
Like POIXMLDocumentPart constructor CallsReadOnlySharedStringsTable(PackagePart, boolean)
, with a value oftrue
to include phonetic runs.- Throws:
IOException
SAXException
- Since:
- POI 3.14-Beta1
-
ReadOnlySharedStringsTable
public ReadOnlySharedStringsTable(PackagePart part, boolean includePhoneticRuns) throws IOException, SAXException Like POIXMLDocumentPart constructor- Throws:
IOException
SAXException
- Since:
- POI 3.14-Beta3
-
-
Method Details
-
readFrom
Read this shared strings table from an XML file.- Parameters:
is
- The input stream containing the XML document.- Throws:
IOException
- if an error occurs while reading.SAXException
- if parsing the XML data fails.
-
getCount
public int getCount()Return an integer representing the total count of strings in the workbook. This count does not include any numbers, it counts only the total of text strings in the workbook.- Specified by:
getCount
in interfaceSharedStrings
- Returns:
- the total count of strings in the workbook
-
getUniqueCount
public int getUniqueCount()Returns an integer representing the total count of unique strings in the Shared String Table. A string is unique even if it is a copy of another string, but has different formatting applied at the character level.- Specified by:
getUniqueCount
in interfaceSharedStrings
- Returns:
- the total count of unique strings in the workbook
-
getEntryAt
Deprecated.usegetItemAt
insteadReturn the string at a given index. Formatting is ignored.- Parameters:
idx
- index of item to return.- Returns:
- the item at the specified position in this Shared String table.
-
getItems
Deprecated.usegetItemAt
insteadReturns all the strings. Formatting is ignored.- Returns:
- a list with all the strings
-
getItemAt
Description copied from interface:SharedStrings
Return a string item by index- Specified by:
getItemAt
in interfaceSharedStrings
- Parameters:
idx
- index of item to return.- Returns:
- the item at the specified position in this Shared String table.
-
startElement
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException - Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
endElement
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
-
characters
Captures characters only if a t(ext) element is open.- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Throws:
SAXException
-
getItemAt
instead