use of org.apache.poi.xssf.eventusermodel.XSSFReader 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;
}
}
Aggregations