Search in sources :

Example 16 with OpenXML4JException

use of org.apache.poi.openxml4j.exceptions.OpenXML4JException in project poi by apache.

the class TestXSSFBugs method bug54764.

@Test
public void bug54764() throws IOException, OpenXML4JException, XmlException {
    OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("54764.xlsx");
    // Check the core properties - will be found but empty, due
    //  to the expansion being too much to be considered valid
    POIXMLProperties props = new POIXMLProperties(pkg);
    assertEquals(null, props.getCoreProperties().getTitle());
    assertEquals(null, props.getCoreProperties().getSubject());
    assertEquals(null, props.getCoreProperties().getDescription());
    // Now check the spreadsheet itself
    try {
        new XSSFWorkbook(pkg).close();
        fail("Should fail as too much expansion occurs");
    } catch (POIXMLException e) {
    // Expected
    }
    pkg.close();
    // Try with one with the entities in the Content Types
    try {
        XSSFTestDataSamples.openSamplePackage("54764-2.xlsx").close();
        fail("Should fail as too much expansion occurs");
    } catch (Exception e) {
    // Expected
    }
    // Check we can still parse valid files after all that
    Workbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
    assertEquals(3, wb.getNumberOfSheets());
    wb.close();
}
Also used : POIXMLProperties(org.apache.poi.POIXMLProperties) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) POIXMLException(org.apache.poi.POIXMLException) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) InvalidOperationException(org.apache.poi.openxml4j.exceptions.InvalidOperationException) POIXMLException(org.apache.poi.POIXMLException) XLSBUnsupportedException(org.apache.poi.xssf.XLSBUnsupportedException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) EncryptedDocumentException(org.apache.poi.EncryptedDocumentException) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Test(org.junit.Test)

Aggregations

OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)16 IOException (java.io.IOException)13 InputStream (java.io.InputStream)7 XmlException (org.apache.xmlbeans.XmlException)7 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)5 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)5 FileNotFoundException (java.io.FileNotFoundException)4 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)4 SAXException (org.xml.sax.SAXException)4 ZipOutputStream (java.util.zip.ZipOutputStream)3 PackageRelationshipCollection (org.apache.poi.openxml4j.opc.PackageRelationshipCollection)3 ZipEntry (java.util.zip.ZipEntry)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 InvalidOperationException (org.apache.poi.openxml4j.exceptions.InvalidOperationException)2 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)2 XSSFBCommentsTable (org.apache.poi.xssf.binary.XSSFBCommentsTable)2 XSSFBSharedStringsTable (org.apache.poi.xssf.binary.XSSFBSharedStringsTable)2 XSSFBStylesTable (org.apache.poi.xssf.binary.XSSFBStylesTable)2 XSSFBReader (org.apache.poi.xssf.eventusermodel.XSSFBReader)2 XSSFBEventBasedExcelExtractor (org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor)2