use of nl.knaw.huygens.timbuctoo.bulkupload.InvalidFileException in project timbuctoo by HuygensING.
the class XlsxLoader method loadData.
@Override
public void loadData(List<Tuple<String, File>> files, Importer importer) throws InvalidFileException, IOException {
try {
RowCellHandler rowCellHandler = makeRowCellHandler(importer);
SAXParserFactory saxFactory = SAXParserFactory.newInstance();
saxFactory.setNamespaceAware(true);
for (Tuple<String, File> file : files) {
OPCPackage pkg = OPCPackage.open(file.getRight().getPath());
XSSFReader xssfReader = new XSSFReader(pkg);
final SharedStringsTable sharedStringsTable = xssfReader.getSharedStringsTable();
XSSFReader.SheetIterator worksheets = (XSSFReader.SheetIterator) xssfReader.getSheetsData();
while (worksheets.hasNext()) {
final InputStream sheet = worksheets.next();
XMLReader sheetParser = saxFactory.newSAXParser().getXMLReader();
sheetParser.setContentHandler(new SheetXmlParser(sharedStringsTable, rowCellHandler));
rowCellHandler.start(worksheets.getSheetName());
sheetParser.parse(new InputSource(sheet));
rowCellHandler.finish();
}
}
} catch (SAXException | OpenXML4JException | ParserConfigurationException e) {
throw new InvalidFileException("Not a valid Excel file", e);
}
}
Aggregations