Class SharedStringsTable
- All Implemented Interfaces:
Closeable,AutoCloseable,SharedStrings
A workbook may contain thousands of cells containing string (non-numeric) data. Furthermore this data is very likely to be repeated across many rows or columns. The goal of implementing a single string table that is shared across the workbook is to improve performance in opening and saving the file by only reading and writing the repetitive information once.
Consider for example a workbook summarizing information for cities within various countries. There may be a column for the name of the country, a column for the name of each city in that country, and a column containing the data for each city. In this case the country name is repetitive, being duplicated in many cells. In many cases the repetition is extensive, and a tremendous savings is realized by making use of a shared string table when saving the workbook. When displaying text in the spreadsheet, the cell table will just contain an index into the string table as the value of a cell, instead of the full string.
The shared string table contains all the necessary information for displaying the string: the text, formatting properties, and phonetic properties (for East Asian languages).
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
POIXMLDocumentPart.RelationPart -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddSharedStringItem(RichTextString string) Add an entry to this Shared String table (a new value is appended to the end).voidclose()Close any open resources, like temp files.intgetCount()Return an integer representing the total count of strings in the workbook.getItemAt(int idx) Return a string item by indexProvide access to the strings in the SharedStringsTableintReturns an integer representing the total count of unique strings in the Shared String Table.voidreadFrom(InputStream is) Read this shared strings table from an XML file.voidwriteTo(OutputStream out) Write this table out as XML.Methods inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
_invokeOnDocumentRead, addRelation, createRelationship, createRelationship, createRelationship, getNextPartNumber, getPackagePart, getParent, getRelationById, getRelationId, getRelationPartById, getRelationParts, getRelations, isCommitted, setCommitted, toString
-
Constructor Details
-
SharedStringsTable
public SharedStringsTable() -
SharedStringsTable
- Throws:
IOException- Since:
- POI 3.14-Beta1
-
-
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.
-
getItemAt
Return a string item by index- Specified by:
getItemAtin interfaceSharedStrings- Parameters:
idx- index of item to return.- Returns:
- the item at the specified position in this Shared String table.
-
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:
getCountin 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:
getUniqueCountin interfaceSharedStrings- Returns:
- the total count of unique strings in the workbook
-
writeTo
Write this table out as XML.- Parameters:
out- The stream to write to.- Throws:
IOException- if an error occurs while writing.
-
close
Close any open resources, like temp files. This method is called byXSSFWorkbook#close().This implementation is empty but subclasses may need to implement some logic.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an error occurs while closing.- Since:
- 4.0.0
-