poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1882466 - /poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
Date Tue, 13 Oct 2020 22:22:58 GMT
Author: nick
Date: Tue Oct 13 22:22:58 2020
New Revision: 1882466

URL: http://svn.apache.org/viewvc?rev=1882466&view=rev
Log:
Add unit test for XLSX embedded in PPT and WorkbookFactory, was already fixed

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

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1882466&r1=1882465&r2=1882466&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Tue Oct
13 22:22:58 2020
@@ -52,10 +52,13 @@ import org.apache.commons.compress.archi
 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.Pack
 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
             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());
+            }
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message