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>(这是一种处理共享字符串表的轻量级方法。大多数文本单元格将引用此处的内容。请注意,如果字符串由具有不同格式的位组成,则每个 SI 条目可以有多个 T 元素。示例输入:
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(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)
Like POIXMLDocumentPart constructor
|
Modifier and Type | Method and Description |
---|---|
void |
characters(char[] ch, int start, int length)
Captures characters only if a t(ext) element is open.
(仅当 at(ext) 元素打开时才捕获字符。)
|
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.
(从 XML 文件中读取此共享字符串表。)
|
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 runs
(调用 {ReadOnlySharedStringsTable(OPCPackage, boolean)},值为 true 以包含语音运行)
pkg
- The
OPCPackage
to use as basis for the shared-strings table.
(pkg - 用作共享字符串表基础的 OPCPackage。)
java.io.IOException
- If reading the data from the package fails.
(java.io.IOException - 如果从包中读取数据失败。)
org.xml.sax.SAXException
- if parsing the XML data fails.
(org.xml.sax.SAXException - 如果解析 XML 数据失败。)
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.
(pkg - 用作共享字符串表基础的 OPCPackage。)
includePhoneticRuns
- whether or not to concatenate phoneticRuns onto the shared string
(includePhoneticRuns - 是否将 phoneticRuns 连接到共享字符串上)
java.io.IOException
- If reading the data from the package fails.
(java.io.IOException - 如果从包中读取数据失败。)
org.xml.sax.SAXException
- if parsing the XML data fails.
(org.xml.sax.SAXException - 如果解析 XML 数据失败。)
public ReadOnlySharedStringsTable(PackagePart part) throws java.io.IOException, org.xml.sax.SAXException
ReadOnlySharedStringsTable(PackagePart, boolean)
, with a value of
true
to include phonetic runs.
(像 POIXMLDocumentPart 构造函数调用 ReadOnlySharedStringsTable(PackagePart, boolean),值为 true 以包含语音运行。)
java.io.IOException
(java.io.IOException)
org.xml.sax.SAXException
(org.xml.sax.SAXException)
public ReadOnlySharedStringsTable(PackagePart part, boolean includePhoneticRuns) throws java.io.IOException, org.xml.sax.SAXException
java.io.IOException
(java.io.IOException)
org.xml.sax.SAXException
(org.xml.sax.SAXException)
public void readFrom(java.io.InputStream is) throws java.io.IOException, org.xml.sax.SAXException
is
- The input stream containing the XML document.
(is - 包含 XML 文档的输入流。)
java.io.IOException
- if an error occurs while reading.
(java.io.IOException - 如果读取时发生错误。)
org.xml.sax.SAXException
- if parsing the XML data fails.
(org.xml.sax.SAXException - 如果解析 XML 数据失败。)
public int getCount()
getCount
in interface
SharedStrings
(接口 SharedStrings 中的 getCount)
public int getUniqueCount()
getUniqueCount
in interface
SharedStrings
(接口 SharedStrings 中的 getUniqueCount)
public RichTextString getItemAt(int idx)
SharedStrings
getItemAt
in interface
SharedStrings
(接口 SharedStrings 中的 getItemAt)
idx
- index of item to return.
(idx - 要返回的项目的索引。)
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.ContentHandler
(接口 org.xml.sax.ContentHandler 中的 startElement)
startElement
in class
org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
(org.xml.sax.SAXException)
public 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.ContentHandler
(org.xml.sax.ContentHandler 接口中的 endElement)
endElement
in class
org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
(org.xml.sax.SAXException)
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
characters
in interface
org.xml.sax.ContentHandler
(org.xml.sax.ContentHandler 接口中的字符)
characters
in class
org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
(org.xml.sax.SAXException)
Copyright 2021 The Apache Software Foundation or its licensors, as applicable.