public class SharedStringsTable extends org.apache.poi.ooxml.POIXMLDocumentPart implements SharedStrings, Closeable
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).
Constructor and Description |
---|
SharedStringsTable() |
SharedStringsTable(PackagePart part) |
Modifier and Type | Method and Description |
---|---|
int |
addEntry(CTRst st)
Deprecated.
use
addSharedStringItem(RichTextString string) instead |
int |
addSharedStringItem(RichTextString string)
Add an entry to this Shared String table (a new value is appended to the end).
|
void |
close()
Close any open resources, like temp files.
|
int |
getCount()
Return an integer representing the total count of strings in the workbook.
|
CTRst |
getEntryAt(int idx)
Deprecated.
use
getItemAt(int idx) instead |
RichTextString |
getItemAt(int idx)
Return a string item by index
|
List<CTRst> |
getItems()
Deprecated.
use
getSharedStringItems instead |
List<RichTextString> |
getSharedStringItems()
Provide access to the strings in the SharedStringsTable
|
int |
getUniqueCount()
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 |
writeTo(OutputStream out)
Write this table out as XML.
|
_invokeOnDocumentRead, addRelation, createRelationship, createRelationship, createRelationship, getPackagePart, getParent, getRelationById, getRelationId, getRelationPartById, getRelationParts, getRelations, isCommited, isCommitted, setCommited, setCommitted, toString
public SharedStringsTable()
public SharedStringsTable(PackagePart part) throws IOException
IOException
public void readFrom(InputStream is) throws IOException
is
- The input stream containing the XML document.IOException
- if an error occurs while reading.@Removal(version="4.2") public CTRst getEntryAt(int idx)
getItemAt(int idx)
insteadidx
- index of item to return.public RichTextString getItemAt(int idx)
getItemAt
in interface SharedStrings
idx
- index of item to return.public int getCount()
getCount
in interface SharedStrings
public int getUniqueCount()
getUniqueCount
in interface SharedStrings
@Removal(version="4.2") public int addEntry(CTRst st)
addSharedStringItem(RichTextString string)
instead
If the Shared String table already contains this CTRst
bean, its index is returned.
Otherwise a new entry is aded.
st
- the entry to addpublic int addSharedStringItem(RichTextString string)
If the Shared String table already contains this string entry, its index is returned. Otherwise a new entry is added.
string
- the entry to add@Removal(version="4.2") public List<CTRst> getItems()
getSharedStringItems
insteadpublic List<RichTextString> getSharedStringItems()
public void writeTo(OutputStream out) throws IOException
out
- The stream to write to.IOException
- if an error occurs while writing.public void close() throws IOException
XSSFWorkbook#close()
.
This implementation is empty but subclasses may need to implement some logic.
close
in interface Closeable
close
in interface AutoCloseable
IOException
- if an error occurs while closing.Copyright © 2010 - 2020 Adobe. All Rights Reserved