protected SharedStrings createSharedStringsTable(XSSFReader xssfReader, OPCPackage container) throws IOException, SAXException { return new ReadOnlySharedStringsTable(container, concatenatePhoneticRuns); }
@Override public RichTextString getItemAt(int idx) { return new XSSFRichTextString(getEntryAt(idx)); }
/** * Like POIXMLDocumentPart constructor * * @since POI 3.14-Beta3 */ public ReadOnlySharedStringsTable(PackagePart part, boolean includePhoneticRuns) throws IOException, SAXException { this.includePhoneticRuns = includePhoneticRuns; readFrom(part.getInputStream()); }
OPCPackage pkg = OPCPackage.open(inputStream); XSSFReader r = new XSSFReader(pkg); ReadOnlySharedStringsTable sst = new ReadOnlySharedStringsTable(pkg); StylesTable styles = r.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) r.getSheetsData();
/** * * @param pkg The {@link OPCPackage} to use as basis for the shared-strings table. * @param includePhoneticRuns whether or not to concatenate phoneticRuns onto the shared string * @since POI 3.14-Beta3 * @throws IOException If reading the data from the package fails. * @throws SAXException if parsing the XML data fails. */ public ReadOnlySharedStringsTable(OPCPackage pkg, boolean includePhoneticRuns) throws IOException, SAXException { this.includePhoneticRuns = includePhoneticRuns; ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType()); // Some workbooks have no shared strings table. if (parts.size() > 0) { PackagePart sstPart = parts.get(0); readFrom(sstPart.getInputStream()); } }
@Override public RichTextString getItemAt(int idx) { return new XSSFRichTextString(getEntryAt(idx)); }
protected SharedStrings createSharedStringsTable(XSSFReader xssfReader, OPCPackage container) throws IOException, SAXException { return new ReadOnlySharedStringsTable(container, concatenatePhoneticRuns); }
/** * Like POIXMLDocumentPart constructor * * @since POI 3.14-Beta3 */ public ReadOnlySharedStringsTable(PackagePart part, boolean includePhoneticRuns) throws IOException, SAXException { this.includePhoneticRuns = includePhoneticRuns; readFrom(part.getInputStream()); }
try { int idx = Integer.parseInt(sstIndex); XSSFRichTextString rtss = new XSSFRichTextString(sharedStringsTable.getEntryAt(idx)); thisStr = rtss.toString();
strings = new ReadOnlySharedStringsTable(container, config.getConcatenatePhoneticRuns()); } catch (InvalidFormatException e) { throw new XmlException(e);
/** * Like POIXMLDocumentPart constructor * * @param part * @param rel_ignored * @throws IOException */ public ReadOnlySharedStringsTable(PackagePart part, PackageRelationship rel_ignored) throws IOException, SAXException { readFrom(part.getInputStream()); }
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(container); XSSFReader xssfReader = new XSSFReader(container); StylesTable styles = xssfReader.getStylesTable();
/** * @param pkg * @throws IOException * @throws SAXException * @throws ParserConfigurationException */ public ReadOnlySharedStringsTable(OPCPackage pkg) throws IOException, SAXException { ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType()); // Some workbooks have no shared strings table. if (parts.size() > 0) { PackagePart sstPart = parts.get(0); readFrom(sstPart.getInputStream()); } }
public static void main(String[] args) throws IOException, SAXException { try (InputStream sourceBytes = new FileInputStream("workbook.xlsx")) { XSSFWorkbook workbook = new XSSFWorkbook(sourceBytes) { /** * Avoid DOM parse of large sheet */ @Override public void parseSheet(java.util.Map<String, XSSFSheet> shIdMap, CTSheet ctSheet) { if (!SHEET_TO_STREAM.equals(ctSheet.getName())) { super.parseSheet(shIdMap, ctSheet); } } }; // Having avoided a DOM-based parse of the sheet, we can stream it instead. ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(workbook.getPackage()); new XSSFSheetXMLHandler(workbook.getStylesSource(), strings, createSheetContentsHandler(), false); workbook.close(); } }
/** * * @param pkg The {@link OPCPackage} to use as basis for the shared-strings table. * @param includePhoneticRuns whether or not to concatenate phoneticRuns onto the shared string * @since POI 3.14-Beta3 * @throws IOException If reading the data from the package fails. * @throws SAXException if parsing the XML data fails. */ public ReadOnlySharedStringsTable(OPCPackage pkg, boolean includePhoneticRuns) throws IOException, SAXException { this.includePhoneticRuns = includePhoneticRuns; ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType()); // Some workbooks have no shared strings table. if (parts.size() > 0) { PackagePart sstPart = parts.get(0); readFrom(sstPart.getInputStream()); } }
/** * Initiates the processing of the XLS workbook file to CSV. * * @throws IOException If reading the data from the package fails. * @throws SAXException if parsing the XML data fails. */ public void process() throws IOException, OpenXML4JException, SAXException { ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage); XSSFReader xssfReader = new XSSFReader(this.xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData(); int index = 0; while (iter.hasNext()) { try (InputStream stream = iter.next()) { String sheetName = iter.getSheetName(); this.output.println(); this.output.println(sheetName + " [index=" + index + "]:"); processSheet(styles, strings, new SheetToCSV(), stream); } ++index; } }
/** * Initiates the processing of the XLS workbook file to CSV. * * @throws IOException * @throws OpenXML4JException * @throws ParserConfigurationException * @throws SAXException */ public List<String> process() throws IOException, OpenXML4JException, ParserConfigurationException, SAXException { ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(this.xlsxPackage); XSSFReader xssfReader = new XSSFReader(this.xlsxPackage); StylesTable styles = xssfReader.getStylesTable(); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData(); int index = 0; while (iter.hasNext()) { if(blankRowNum == 10)break; InputStream stream = iter.next(); String sheetName = iter.getSheetName(); results.add(ExcelValidator.SHEET_NAME_PREFIX + sheetName); processSheet(styles, strings, new SheetToCSV(), stream); stream.close(); ++index; } return results; }
protected <T> void unmarshal0(Class<T> type, Consumer<? super T> consumer, OPCPackage open) throws ParserConfigurationException, IOException, SAXException, OpenXML4JException { ReadOnlySharedStringsTable readOnlySharedStringsTable = new ReadOnlySharedStringsTable(open); XSSFReader workbookReader = new XSSFReader(open); StylesTable styles = workbookReader.getStylesTable(); XMLReader reader = SAXHelper.newXMLReader(); InputSource is = new InputSource(workbookReader.getWorkbookData()); reader.setContentHandler(new WorkBookContentHandler(options)); reader.parse(is); WorkBookContentHandler wbch = (WorkBookContentHandler) reader.getContentHandler(); List<WorkBookSheet> sheets = wbch.getSheets(); int requestedIndex = options.sheetIndex(); int nonHiddenSheetIndex = 0; int sheetCounter = 0; SheetIterator iter = (SheetIterator) workbookReader.getSheetsData(); while (iter.hasNext()) { try (InputStream stream = iter.next()) { WorkBookSheet wbs = sheets.get(sheetCounter); if (wbs.getState().equals("visible")) { if (nonHiddenSheetIndex == requestedIndex) { processSheet(styles, reader, readOnlySharedStringsTable, type, stream, consumer); return; } nonHiddenSheetIndex++; } } sheetCounter++; } }
/** * Returns a DataFrame parsed from the stream specified stream * * @return the DataFrame parsed from stream * @throws IOException if there stream read error */ private DataFrame<R, String> parse(ExcelSourceOptions<R> options, OPCPackage opcPackage) throws IOException { try { ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(opcPackage); XSSFReader xssfReader = new XSSFReader(opcPackage); XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader.getSheetsData(); try (InputStream inputStream = getSheetForParsing( options, iter)) { StylesTable styles = xssfReader.getStylesTable(); XMLReader sheetParser = SAXHelper.newXMLReader(); final ExcelXSSFSheetContentHandler sheetContentsHandler = new ExcelXSSFSheetContentHandler(options); DataFormatter formatter = new DataFormatter(); ContentHandler contentHandler = new XSSFSheetXMLHandler(styles, null, strings, sheetContentsHandler, formatter, false); sheetParser.setContentHandler(contentHandler); sheetParser.parse(new InputSource(inputStream)); sheetContentsHandler.endProcess(); return sheetContentsHandler.getFrame(); } catch (InvalidFormatException e) { throw new DataFrameException("Failed to parse Excel file - invalid format", e); } catch (ParserConfigurationException e) { throw new DataFrameException("Failed to parse Excel file - parser configuration issue", e); } } catch (OpenXML4JException|SAXException ex) { throw new DataFrameException("Failed to parse Excel file", ex); } }
this.pushSST = new ReadOnlySharedStringsTable(pkg); } else if (HadoopOfficeReadConfiguration.OPTION_LOWFOOTPRINT_PARSER_STAX.equalsIgnoreCase(this.hocr.getLowFootprintParser())) { List<PackagePart> pkgParts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());