From 8dde2730170f243d31e2dc23e0e6f319363c3365 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 13 Oct 2020 22:22:58 +0000 Subject: [PATCH] Add unit test for XLSX embedded in PPT and WorkbookFactory, was already fixed git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882466 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/TestXSSFBugs.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 22cf3f3a7a..246088f4c3 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -52,10 +52,13 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; import org.apache.poi.POIDataSamples; import org.apache.poi.common.usermodel.HyperlinkType; +import org.apache.poi.hslf.usermodel.HSLFObjectData; +import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.hslf.HSLFTestDataSamples; import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart; import org.apache.poi.ooxml.POIXMLException; @@ -70,6 +73,8 @@ import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.util.ZipSecureFile; +import org.apache.poi.poifs.filesystem.DocumentEntry; +import org.apache.poi.poifs.filesystem.DocumentInputStream; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.ITestDataProvider; import org.apache.poi.ss.SpreadsheetVersion; @@ -3568,4 +3573,42 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { int activeSheet = wb.getActiveSheetIndex(); } } + + @Test + public void testXLSXinPPT() throws Exception { + try (HSLFSlideShow ppt = new HSLFSlideShow( + HSLFTestDataSamples.openSampleFileStream("testPPT_oleWorkbook.ppt"))) { + assertEquals(1, ppt.getEmbeddedObjects().length); + + HSLFObjectData data = ppt.getEmbeddedObjects()[0]; + assertEquals(null, data.getFileName()); + + // Will be OOXML wrapped in OLE2, not directly SpreadSheet + POIFSFileSystem fs = new POIFSFileSystem(data.getInputStream()); + assertEquals(true, fs.getRoot().hasEntry("Package")); + assertEquals(false, fs.getRoot().hasEntry("Workbook")); + + // Can fetch Package to get OOXML + DocumentInputStream dis = new DocumentInputStream((DocumentEntry)fs.getRoot().getEntry("Package")); + try (OPCPackage pkg = OPCPackage.open(dis)) { + XSSFWorkbook wb = new XSSFWorkbook(pkg); + assertEquals(1, wb.getNumberOfSheets()); + wb.close(); + } + + // Via the XSSF Factory + XSSFWorkbookFactory xssfFactory = new XSSFWorkbookFactory(); + try (XSSFWorkbook wb = xssfFactory.create(fs.getRoot(), null)) { + assertEquals(1, wb.getNumberOfSheets()); + } + + // Or can open via the normal Factory, as stream or OLE2 + try (Workbook wb = WorkbookFactory.create(fs)) { + assertEquals(1, wb.getNumberOfSheets()); + } + try (Workbook wb = WorkbookFactory.create(data.getInputStream())) { + assertEquals(1, wb.getNumberOfSheets()); + } + } + } } -- 2.39.5