@Override protected void onDocumentRead() throws IOException { try { WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); this.workbook = doc.getWorkbook();
WorkbookDocument wd = WorkbookDocument.Factory.parse(workbookDataXML); this.isDate1904 = wd.getWorkbook().getWorkbookPr().getDate1904();
@Override protected void onDocumentRead() throws IOException { try { WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS); this.workbook = doc.getWorkbook();
protected void onDocumentRead() throws IOException { try { WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream()); this.workbook = doc.getWorkbook();
/** * Construct a new SheetIterator * * @param wb package part holding workbook.xml */ private SheetIterator(PackagePart wb) throws IOException { /** * The order of sheets is defined by the order of CTSheet elements in workbook.xml */ try { //step 1. Map sheet's relationship Id and the corresponding PackagePart sheetMap = new HashMap<String, PackagePart>(); for(PackageRelationship rel : wb.getRelationships()){ if(rel.getRelationshipType().equals(XSSFRelation.WORKSHEET.getRelation()) || rel.getRelationshipType().equals(XSSFRelation.CHARTSHEET.getRelation())){ PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI()); sheetMap.put(rel.getId(), wb.getPackage().getPart(relName)); } } //step 2. Read array of CTSheet elements, wrap it in a ArayList and construct an iterator //Note, using XMLBeans might be expensive, consider refactoring to use SAX or a plain regexp search CTWorkbook wbBean = WorkbookDocument.Factory.parse(wb.getInputStream()).getWorkbook(); sheetIterator = wbBean.getSheets().getSheetList().iterator(); } catch (InvalidFormatException e){ throw new POIXMLException(e); } catch (XmlException e){ throw new POIXMLException(e); } }
private void saveWorkBook(List<String> savedParts, XSSFWorkbook workBook, ZipOutputStream out) throws IOException, OpenXML4JException { removePrintAreas(workBook); PackagePart part = workBook.getPackagePart(); String entryName = getEntryName(part); WorkbookDocument doc = WorkbookDocument.Factory.newInstance(); doc.setWorkbook(workBook.getCTWorkbook()); out.putNextEntry(new ZipEntry(entryName)); doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS); out.closeEntry(); savedParts.add(entryName); // Saving relationship part if (part.hasRelationships()) { PackagePartName relationshipPartName = PackagingURIHelper .getRelationshipPartName(part.getPartName()); ZipPartMarshaller.marshallRelationshipPart(part.getRelationships(), relationshipPartName, out); savedParts.add(getEntryName(part)); } }
public XlsxSaxAnalyser(AnalysisContext analysisContext) throws IOException, OpenXML4JException, XmlException { this.analysisContext = analysisContext; analysisContext.setCurrentRowNum(0); this.xssfReader = new XSSFReader(OPCPackage.open(analysisContext.getInputStream())); this.sharedStringsTable = this.xssfReader.getSharedStringsTable(); InputStream workbookXml = xssfReader.getWorkbookData(); WorkbookDocument ctWorkbook = WorkbookDocument.Factory.parse(workbookXml); CTWorkbook wb = ctWorkbook.getWorkbook(); CTWorkbookPr prefix = wb.getWorkbookPr(); if (prefix != null) { this.use1904WindowDate = prefix.getDate1904(); } this.analysisContext.setUse1904WindowDate(use1904WindowDate); XSSFReader.SheetIterator ite; sheetSourceList = new ArrayList<SheetSource>(); ite = (XSSFReader.SheetIterator)xssfReader.getSheetsData(); while (ite.hasNext()) { InputStream inputStream = ite.next(); String sheetName = ite.getSheetName(); SheetSource sheetSource = new SheetSource(sheetName, inputStream); sheetSourceList.add(sheetSource); } }