use of org.apache.poi.xssf.model.SharedStringsTable in project yyl_example by Relucent.
the class XlsxParser method doParse.
private void doParse(InputStream input) throws IOException, OpenXML4JException, SAXException {
OPCPackage pkg = OPCPackage.open(input);
XSSFReader xssfReader = new XSSFReader(pkg);
SharedStringsTable table = xssfReader.getSharedStringsTable();
XlsxHandler handler = new XlsxHandler(table);
XMLReader parser = createXMLReader(table, handler);
Iterator<InputStream> sheets = xssfReader.getSheetsData();
int sheetIndex = 0;
while (sheets.hasNext()) {
handler.reader = sheetReaders.get(sheetIndex++);
try (InputStream sheet = sheets.next()) {
if (handler.reader != null) {
InputSource source = new InputSource(sheet);
parser.parse(source);
}
}
}
}
use of org.apache.poi.xssf.model.SharedStringsTable 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);
}
}
use of org.apache.poi.xssf.model.SharedStringsTable in project pentaho-kettle by pentaho.
the class StaxPoiSheetTest method mockSharedStringsTable.
private SharedStringsTable mockSharedStringsTable(String... strings) {
SharedStringsTable sst = new SharedStringsTable();
for (String str : strings) {
CTRst st = CTRst.Factory.newInstance();
st.setT(str);
sst.addEntry(st);
}
return sst;
}
Aggregations