Search in sources :

Example 6 with ReadOnlySharedStringsTable

use of org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable in project poi by apache.

the class XSSFEventBasedExcelExtractor method getText.

/**
    * Processes the file and returns the text
    */
public String getText() {
    try {
        ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(container, concatenatePhoneticRuns);
        XSSFReader xssfReader = new XSSFReader(container);
        StylesTable styles = xssfReader.getStylesTable();
        XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
        StringBuffer text = new StringBuffer();
        SheetTextExtractor sheetExtractor = new SheetTextExtractor();
        while (iter.hasNext()) {
            InputStream stream = iter.next();
            if (includeSheetNames) {
                text.append(iter.getSheetName());
                text.append('\n');
            }
            CommentsTable comments = includeCellComments ? iter.getSheetComments() : null;
            processSheet(sheetExtractor, styles, comments, strings, stream);
            if (includeHeadersFooters) {
                sheetExtractor.appendHeaderText(text);
            }
            sheetExtractor.appendCellText(text);
            if (includeTextBoxes) {
                processShapes(iter.getShapes(), text);
            }
            if (includeHeadersFooters) {
                sheetExtractor.appendFooterText(text);
            }
            sheetExtractor.reset();
            stream.close();
        }
        return text.toString();
    } catch (IOException e) {
        LOGGER.log(POILogger.WARN, e);
        return null;
    } catch (SAXException se) {
        LOGGER.log(POILogger.WARN, se);
        return null;
    } catch (OpenXML4JException o4je) {
        LOGGER.log(POILogger.WARN, o4je);
        return null;
    }
}
Also used : ReadOnlySharedStringsTable(org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) InputStream(java.io.InputStream) StylesTable(org.apache.poi.xssf.model.StylesTable) IOException(java.io.IOException) XSSFReader(org.apache.poi.xssf.eventusermodel.XSSFReader) CommentsTable(org.apache.poi.xssf.model.CommentsTable) SAXException(org.xml.sax.SAXException)

Aggregations

InputStream (java.io.InputStream)6 ReadOnlySharedStringsTable (org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable)6 XSSFReader (org.apache.poi.xssf.eventusermodel.XSSFReader)5 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)4 StylesTable (org.apache.poi.xssf.model.StylesTable)3 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)2 CommentsTable (org.apache.poi.xssf.model.CommentsTable)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)1 DataFormatter (org.apache.poi.ss.usermodel.DataFormatter)1 XSSFSheetXMLHandler (org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler)1 XSSFShape (org.apache.poi.xssf.usermodel.XSSFShape)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1 XmlException (org.apache.xmlbeans.XmlException)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1