Class ReadOnlySharedStringsTable

  • All Implemented Interfaces:
    SharedStrings, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

    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>
     
    • Field Summary

      Fields 
      Modifier and Type Field 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.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method 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.
      java.lang.String getEntryAt​(int idx)
      Deprecated.
      use getItemAt instead
      RichTextString getItemAt​(int idx)
      Return a string item by index
      java.util.List<java.lang.String> getItems()
      Deprecated.
      use getItemAt instead
      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)  
      • 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
    • Field Detail

      • includePhoneticRuns

        protected final boolean includePhoneticRuns
      • count

        protected int count
        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.
      • uniqueCount

        protected int uniqueCount
        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.
    • Constructor Detail

      • ReadOnlySharedStringsTable

        public ReadOnlySharedStringsTable​(OPCPackage pkg)
                                   throws java.io.IOException,
                                          org.xml.sax.SAXException
        Calls {ReadOnlySharedStringsTable(OPCPackage, boolean)} with a value of true for including phonetic runs
        Parameters:
        pkg - The OPCPackage to use as basis for the shared-strings table.
        Throws:
        java.io.IOException - If reading the data from the package fails.
        org.xml.sax.SAXException - if parsing the XML data fails.
      • ReadOnlySharedStringsTable

        public ReadOnlySharedStringsTable​(OPCPackage pkg,
                                          boolean includePhoneticRuns)
                                   throws java.io.IOException,
                                          org.xml.sax.SAXException
        Parameters:
        pkg - The OPCPackage to use as basis for the shared-strings table.
        includePhoneticRuns - whether or not to concatenate phoneticRuns onto the shared string
        Throws:
        java.io.IOException - If reading the data from the package fails.
        org.xml.sax.SAXException - if parsing the XML data fails.
        Since:
        POI 3.14-Beta3
      • ReadOnlySharedStringsTable

        public ReadOnlySharedStringsTable​(PackagePart part)
                                   throws java.io.IOException,
                                          org.xml.sax.SAXException
        Like POIXMLDocumentPart constructor Calls ReadOnlySharedStringsTable(PackagePart, boolean), with a value of true to include phonetic runs.
        Throws:
        java.io.IOException
        org.xml.sax.SAXException
        Since:
        POI 3.14-Beta1
      • ReadOnlySharedStringsTable

        public ReadOnlySharedStringsTable​(PackagePart part,
                                          boolean includePhoneticRuns)
                                   throws java.io.IOException,
                                          org.xml.sax.SAXException
        Like POIXMLDocumentPart constructor
        Throws:
        java.io.IOException
        org.xml.sax.SAXException
        Since:
        POI 3.14-Beta3
    • Method Detail

      • readFrom

        public void readFrom​(java.io.InputStream is)
                      throws java.io.IOException,
                             org.xml.sax.SAXException
        Read this shared strings table from an XML file.
        Parameters:
        is - The input stream containing the XML document.
        Throws:
        java.io.IOException - if an error occurs while reading.
        org.xml.sax.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 interface SharedStrings
        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 interface SharedStrings
        Returns:
        the total count of unique strings in the workbook
      • getEntryAt

        @Removal(version="4.2")
        @Deprecated
        public java.lang.String getEntryAt​(int idx)
        Deprecated.
        use getItemAt instead
        Return 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

        @Removal(version="4.2")
        @Deprecated
        public java.util.List<java.lang.String> getItems()
        Deprecated.
        use getItemAt instead
        Returns all the strings. Formatting is ignored.
        Returns:
        a list with all the strings
      • getItemAt

        public RichTextString getItemAt​(int idx)
        Description copied from interface: SharedStrings
        Return a string item by index
        Specified by:
        getItemAt in interface SharedStrings
        Parameters:
        idx - index of item to return.
        Returns:
        the item at the specified position in this Shared String table.
      • startElement

        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
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Overrides:
        startElement in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • endElement

        public void endElement​(java.lang.String uri,
                               java.lang.String localName,
                               java.lang.String name)
                        throws org.xml.sax.SAXException
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Overrides:
        endElement in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • characters

        public void characters​(char[] ch,
                               int start,
                               int length)
                        throws org.xml.sax.SAXException
        Captures characters only if a t(ext) element is open.
        Specified by:
        characters in interface org.xml.sax.ContentHandler
        Overrides:
        characters in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException