]> source.dussan.org Git - poi.git/commitdiff
Add unit test for XLSX embedded in PPT and WorkbookFactory, was already fixed
authorNick Burch <nick@apache.org>
Tue, 13 Oct 2020 22:22:58 +0000 (22:22 +0000)
committerNick Burch <nick@apache.org>
Tue, 13 Oct 2020 22:22:58 +0000 (22:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882466 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

index 22cf3f3a7af769fc55ba6b5f960c56b10f424a4f..246088f4c3237e3fa6a00b546161a0591eda5212 100644 (file)
@@ -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());
+            }
+        }
+    }
 }