/**
* Table with the styles used for formatting
*/
- private Styles stylesTable;
+ private final Styles stylesTable;
/**
* Table with cell comments
*/
- private Comments comments;
+ private final Comments comments;
/**
* Read only access to the shared strings table, for looking
* up (most) string cell's contents
*/
- private SharedStrings sharedStringsTable;
+ private final SharedStrings sharedStringsTable;
/**
* Where our text is going
private int rowNum;
private int nextRowNum; // some sheets do not have rowNums, Excel can read them so we should try to handle them correctly as well
private String cellRef;
- private boolean formulasNotResults;
+ private final boolean formulasNotResults;
// Gathers characters as they are seen.
- private StringBuilder value = new StringBuilder(64);
- private StringBuilder formula = new StringBuilder(64);
- private StringBuilder headerFooter = new StringBuilder(64);
+ private final StringBuilder value = new StringBuilder(64);
+ private final StringBuilder formula = new StringBuilder(64);
+ private final StringBuilder headerFooter = new StringBuilder(64);
private Queue<CellAddress> commentCellRefs;
case SST_STRING:
String sstIndex = value.toString();
- try {
- int idx = Integer.parseInt(sstIndex);
- RichTextString rtss = sharedStringsTable.getItemAt(idx);
- thisStr = rtss.toString();
- }
- catch (NumberFormatException ex) {
- LOG.atError().withThrowable(ex).log("Failed to parse SST index '{}'", sstIndex);
+ if (sstIndex.length() > 0) {
+ try {
+ int idx = Integer.parseInt(sstIndex);
+ RichTextString rtss = sharedStringsTable.getItemAt(idx);
+ thisStr = rtss.toString();
+ } catch (NumberFormatException ex) {
+ LOG.atError().withThrowable(ex).log("Failed to parse SST index '{}'", sstIndex);
+ }
}
break;
}
}
}
+
+ @Test
+ public void testNumber() throws Exception {
+ try (OPCPackage xlsxPackage = OPCPackage.open(_ssTests.openResourceAsStream("sample.xlsx"))) {
+ final XSSFReader reader = new XSSFReader(xlsxPackage);
+
+ final Iterator<InputStream> iter = reader.getSheetsData();
+
+ try (InputStream stream = iter.next()) {
+ final XMLReader sheetParser = XMLHelper.getSaxParserFactory().newSAXParser().getXMLReader();
+
+ sheetParser.setContentHandler(new XSSFSheetXMLHandler(reader.getStylesTable(),
+ new ReadOnlySharedStringsTable(xlsxPackage), new SheetContentsHandler() {
+ @Override
+ public void startRow(final int rowNum) {
+ }
+
+ @Override
+ public void endRow(final int rowNum) {
+ }
+
+ @Override
+ public void cell(final String cellReference, final String formattedValue,
+ final XSSFComment comment) {
+ }
+ }, false));
+
+ sheetParser.parse(new InputSource(stream));
+ }
+ }
+ }
}