make xssf streaming code more extensible

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1836795 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2018-07-27 09:19:58 +00:00
parent ad4f5ea6d2
commit d2d9202772
2 changed files with 85 additions and 88 deletions

View File

@ -168,6 +168,7 @@ public class XSSFReader {
/**
* Returns an InputStream to read the contents of the
* specified Sheet.
*
* @param relId The relationId of the sheet, from a r:id on the workbook
*/
public InputStream getSheet(String relId) throws IOException, InvalidFormatException {
@ -342,9 +343,8 @@ public class XSSFReader {
PackagePart commentsPart = sheetPkg.getPackage().getPart(commentsName);
return new CommentsTable(commentsPart);
}
} catch (InvalidFormatException e) {
return null;
} catch (IOException e) {
} catch (InvalidFormatException|IOException e) {
LOGGER.log(POILogger.WARN, e);
return null;
}
return null;
@ -372,11 +372,8 @@ public class XSSFReader {
XSSFDrawing drawing = new XSSFDrawing(drawingsPart);
shapes.addAll(drawing.getShapes());
}
} catch (XmlException e){
return null;
} catch (InvalidFormatException e) {
return null;
} catch (IOException e) {
} catch (XmlException|InvalidFormatException|IOException e) {
LOGGER.log(POILogger.WARN, e);
return null;
}
return shapes;

View File

@ -58,16 +58,16 @@ public class XSSFEventBasedExcelExtractor extends POIXMLTextExtractor
private static final POILogger LOGGER = POILogFactory.getLogger(XSSFEventBasedExcelExtractor.class);
private OPCPackage container;
private POIXMLProperties properties;
protected OPCPackage container;
protected POIXMLProperties properties;
private Locale locale;
private boolean includeTextBoxes = true;
private boolean includeSheetNames = true;
private boolean includeCellComments;
private boolean includeHeadersFooters = true;
private boolean formulasNotResults;
private boolean concatenatePhoneticRuns = true;
protected Locale locale;
protected boolean includeTextBoxes = true;
protected boolean includeSheetNames = true;
protected boolean includeCellComments;
protected boolean includeHeadersFooters = true;
protected boolean formulasNotResults;
protected boolean concatenatePhoneticRuns = true;
public XSSFEventBasedExcelExtractor(String path) throws XmlException, OpenXML4JException, IOException {
this(OPCPackage.open(path));
@ -254,7 +254,7 @@ public class XSSFEventBasedExcelExtractor extends POIXMLTextExtractor
}
}
protected SharedStrings createSharedStringsTable(OPCPackage container, boolean concatenatePhoneticRuns)
protected SharedStrings createSharedStringsTable(XSSFReader xssfReader, OPCPackage container)
throws IOException, SAXException {
return new ReadOnlySharedStringsTable(container, concatenatePhoneticRuns);
}
@ -264,8 +264,8 @@ public class XSSFEventBasedExcelExtractor extends POIXMLTextExtractor
*/
public String getText() {
try {
SharedStrings strings = createSharedStringsTable(container, concatenatePhoneticRuns);
XSSFReader xssfReader = new XSSFReader(container);
SharedStrings strings = createSharedStringsTable(xssfReader, container);
StylesTable styles = xssfReader.getStylesTable();
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
StringBuilder text = new StringBuilder(64);