Search in sources :

Example 1 with XSSFBHyperlinksTable

use of org.apache.poi.xssf.binary.XSSFBHyperlinksTable in project poi by apache.

the class XSSFBEventBasedExcelExtractor method getText.

/**
     * Processes the file and returns the text
     */
public String getText() {
    try {
        XSSFBSharedStringsTable strings = new XSSFBSharedStringsTable(getPackage());
        XSSFBReader xssfbReader = new XSSFBReader(getPackage());
        XSSFBStylesTable styles = xssfbReader.getXSSFBStylesTable();
        XSSFBReader.SheetIterator iter = (XSSFBReader.SheetIterator) xssfbReader.getSheetsData();
        StringBuffer text = new StringBuffer();
        SheetTextExtractor sheetExtractor = new SheetTextExtractor();
        XSSFBHyperlinksTable hyperlinksTable = null;
        while (iter.hasNext()) {
            InputStream stream = iter.next();
            if (getIncludeSheetNames()) {
                text.append(iter.getSheetName());
                text.append('\n');
            }
            if (handleHyperlinksInCells) {
                hyperlinksTable = new XSSFBHyperlinksTable(iter.getSheetPart());
            }
            XSSFBCommentsTable comments = getIncludeCellComments() ? iter.getXSSFBSheetComments() : null;
            processSheet(sheetExtractor, styles, comments, strings, stream);
            if (getIncludeHeadersFooters()) {
                sheetExtractor.appendHeaderText(text);
            }
            sheetExtractor.appendCellText(text);
            if (getIncludeTextBoxes()) {
                processShapes(iter.getShapes(), text);
            }
            if (getIncludeHeadersFooters()) {
                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 : XSSFBReader(org.apache.poi.xssf.eventusermodel.XSSFBReader) XSSFBCommentsTable(org.apache.poi.xssf.binary.XSSFBCommentsTable) InputStream(java.io.InputStream) IOException(java.io.IOException) XSSFBStylesTable(org.apache.poi.xssf.binary.XSSFBStylesTable) SAXException(org.xml.sax.SAXException) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) XSSFBHyperlinksTable(org.apache.poi.xssf.binary.XSSFBHyperlinksTable) XSSFBSharedStringsTable(org.apache.poi.xssf.binary.XSSFBSharedStringsTable)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)1 XSSFBCommentsTable (org.apache.poi.xssf.binary.XSSFBCommentsTable)1 XSSFBHyperlinksTable (org.apache.poi.xssf.binary.XSSFBHyperlinksTable)1 XSSFBSharedStringsTable (org.apache.poi.xssf.binary.XSSFBSharedStringsTable)1 XSSFBStylesTable (org.apache.poi.xssf.binary.XSSFBStylesTable)1 XSSFBReader (org.apache.poi.xssf.eventusermodel.XSSFBReader)1 SAXException (org.xml.sax.SAXException)1