/** * Returns an Iterator which will let you get at all the * different Sheets in turn. * Each sheet's InputStream is only opened when fetched * from the Iterator. It's up to you to close the * InputStreams when done with each one. */ @Override public Iterator<InputStream> getSheetsData() throws IOException, InvalidFormatException { return new SheetIterator(workbookPart); }
private void endRow(int row) { if (lastEndedRow == row) { return; } handler.endRow(row); lastEndedRow = row; }
/** * Returns name of the current sheet * * @return name of the current sheet */ public String getSheetName() { return xssfSheetRef.getName(); }
private XSSFReader mockXSSFReader( final String sheetId, final String sheetContent, final SharedStringsTable sst, final StylesTable styles ) throws Exception { XSSFReader reader = mock( XSSFReader.class ); when( reader.getSharedStringsTable() ).thenReturn( sst ); when( reader.getStylesTable() ).thenReturn( styles ); when( reader.getSheet( sheetId ) ).thenAnswer( new Answer<InputStream>() { public InputStream answer( InvocationOnMock invocation ) throws Throwable { return IOUtils.toInputStream( sheetContent, "UTF-8" ); } } ); return reader; }
protected SharedStrings createSharedStringsTable(XSSFReader xssfReader, OPCPackage container) throws IOException, SAXException { return new ReadOnlySharedStringsTable(container, concatenatePhoneticRuns); }
private void resetSheetReader() throws IOException, XMLStreamException, InvalidFormatException { sheetReader.close(); sheetStream.close(); sheetStream = xssfReader.getSheet( sheetId ); XMLInputFactory factory = XMLInputFactory.newInstance(); sheetReader = factory.createXMLStreamReader( sheetStream ); }
/** * In Excel 2013, the absolute path where the file was last saved may be stored in * the {@link XSSFBRecordType#BrtAbsPath15} record. The equivalent in ooxml is * <x15ac:absPath>. * * @return absolute path or <code>null</code> if it could not be found. * @throws IOException when there's a problem with the workbook part's stream */ public String getAbsPathMetadata() throws IOException { try (InputStream is = workbookPart.getInputStream()) { PathExtractor p = new PathExtractor(is); p.parse(); return p.getPath(); } }
Iterator<XSSFSheetRef> createSheetIteratorFromWB(PackagePart wb) throws IOException { SheetRefLoader sheetRefLoader = new SheetRefLoader(wb.getInputStream()); sheetRefLoader.parse(); return sheetRefLoader.getSheets().iterator(); }
private void dumpEmptyCellComment(CellAddress cellAddress, XSSFBComment comment) { handler.cell(cellAddress.formatAsString(), null, comment); }
private void addWorksheet(byte[] data) { //try to parse the BrtBundleSh //if there's an exception, catch it and //try to figure out if this is one of the old beta-created xlsb files //or if this is a general exception try { tryToAddWorksheet(data); } catch (XSSFBParseException e) { if (tryOldFormat(data)) { log.log(POILogger.WARN, "This file was written with a beta version of Excel. "+ "POI will try to parse the file as a regular xlsb."); } else { throw e; } } }
/** * Returns an Iterator which will let you get at all the * different Sheets in turn. * Each sheet's InputStream is only opened when fetched * from the Iterator. It's up to you to close the * InputStreams when done with each one. */ public Iterator<InputStream> getSheetsData() throws IOException, InvalidFormatException { return new SheetIterator(workbookPart); }
/** * Like POIXMLDocumentPart constructor * * @since POI 3.14-Beta3 */ public ReadOnlySharedStringsTable(PackagePart part, boolean includePhoneticRuns) throws IOException, SAXException { this.includePhoneticRuns = includePhoneticRuns; readFrom(part.getInputStream()); }
private void startRow(int row) { if (row == lastStartedRow) { return; } if (lastStartedRow != lastEndedRow) { endRow(lastStartedRow); } handler.startRow(row); lastStartedRow = row; }
@Override public RichTextString getItemAt(int idx) { return new XSSFRichTextString(getEntryAt(idx)); }
private void outputHeaderFooter(XSSFBHeaderFooter headerFooter) { String text = headerFooter.getString(); if (text != null && text.trim().length() > 0) { handler.headerFooter(text, headerFooter.isHeader(), headerFooter.getHeaderFooterTypeLabel()); } }
/** * Accepts objects needed while parsing. * * @param styles Table of styles * @param strings Table of shared strings */ public XSSFSheetXMLHandler( Styles styles, Comments comments, SharedStrings strings, SheetContentsHandler sheetContentsHandler, DataFormatter dataFormatter, boolean formulasNotResults) { this.stylesTable = styles; this.comments = comments; this.sharedStringsTable = strings; this.output = sheetContentsHandler; this.formulasNotResults = formulasNotResults; this.nextDataType = xssfDataType.NUMBER; this.formatter = dataFormatter; init(comments); }
public PackagePart getSheetPart() { String sheetId = xssfSheetRef.getId(); return sheetMap.get(sheetId); }
@Override public void handleRecord(int recordType, byte[] data) throws XSSFBParseException { if (recordType == XSSFBRecordType.BrtBundleSh.getId()) { addWorksheet(data); } }
/** * Output an empty-cell comment. */ private void outputEmptyCellComment(CellAddress cellRef) { XSSFComment comment = comments.findCellComment(cellRef); output.cell(cellRef.formatAsString(), null, comment); }
private void handleCellValue(String formattedValue) { CellAddress cellAddress = new CellAddress(currentRow, cellBuffer.getColNum()); XSSFBComment comment = null; if (comments != null) { comment = comments.get(cellAddress); } handler.cell(cellAddress.formatAsString(), formattedValue, comment); }