Search in sources :

Example 51 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class TestXSSFReader method test50119.

/**
    * Iterating over a workbook with chart sheets in it, using the
    *  XSSFReader method
    * @throws Exception
    */
public void test50119() throws Exception {
    OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("WithChartSheet.xlsx");
    XSSFReader r = new XSSFReader(pkg);
    XSSFReader.SheetIterator it = (XSSFReader.SheetIterator) r.getSheetsData();
    while (it.hasNext()) {
        InputStream stream = it.next();
        stream.close();
    }
}
Also used : InputStream(java.io.InputStream) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Example 52 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class TestXSSFReader method testBug57914.

public void testBug57914() throws Exception {
    OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("57914.xlsx");
    final XSSFReader r;
    // this test as well
    try {
        r = new XSSFReader(pkg);
        fail("This will fail until bug 57699 is fixed");
    } catch (POIXMLException e) {
        assertContains(e.getMessage(), "57699");
        return;
    }
    XSSFReader.SheetIterator it = (XSSFReader.SheetIterator) r.getSheetsData();
    String text = getShapesString(it);
    assertContains(text, "Line 1");
    assertContains(text, "Line 2");
    assertContains(text, "Line 3");
}
Also used : POIXMLException(org.apache.poi.POIXMLException) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Example 53 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class TestXSSFReader method testComments.

public void testComments() throws Exception {
    OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("comments.xlsx");
    XSSFReader r = new XSSFReader(pkg);
    XSSFReader.SheetIterator it = (XSSFReader.SheetIterator) r.getSheetsData();
    int count = 0;
    while (it.hasNext()) {
        count++;
        InputStream inp = it.next();
        inp.close();
        if (count == 1) {
            assertNotNull(it.getSheetComments());
            CommentsTable ct = it.getSheetComments();
            assertEquals(1, ct.getNumberOfAuthors());
            assertEquals(3, ct.getNumberOfComments());
        } else {
            assertNull(it.getSheetComments());
        }
    }
    assertEquals(3, count);
}
Also used : InputStream(java.io.InputStream) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) CommentsTable(org.apache.poi.xssf.model.CommentsTable)

Example 54 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class TestXSSFReader method testStyles.

public void testStyles() throws Exception {
    OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx"));
    XSSFReader r = new XSSFReader(pkg);
    assertEquals(3, r.getStylesTable().getFonts().size());
    assertEquals(0, r.getStylesTable().getNumDataFormats());
    // The Styles Table should have the themes associated with it too
    assertNotNull(r.getStylesTable().getTheme());
    // Check we get valid data for the two
    assertNotNull(r.getStylesData());
    assertNotNull(r.getThemesData());
}
Also used : OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Example 55 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class TestXSSFReader method testGetBits.

public void testGetBits() throws Exception {
    OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("SampleSS.xlsx"));
    XSSFReader r = new XSSFReader(pkg);
    assertNotNull(r.getWorkbookData());
    assertNotNull(r.getSharedStringsData());
    assertNotNull(r.getStylesData());
    assertNotNull(r.getSharedStringsTable());
    assertNotNull(r.getStylesTable());
}
Also used : OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Aggregations

OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)116 Test (org.junit.Test)54 InputStream (java.io.InputStream)29 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)25 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)21 File (java.io.File)19 IOException (java.io.IOException)17 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)13 SignatureConfig (org.apache.poi.poifs.crypt.dsig.SignatureConfig)10 SignatureInfo (org.apache.poi.poifs.crypt.dsig.SignatureInfo)10 XSSFReader (org.apache.poi.xssf.eventusermodel.XSSFReader)10 OutputStream (java.io.OutputStream)9 ArrayList (java.util.ArrayList)9 FileOutputStream (java.io.FileOutputStream)8 InvalidOperationException (org.apache.poi.openxml4j.exceptions.InvalidOperationException)8 XmlException (org.apache.xmlbeans.XmlException)8 FileInputStream (java.io.FileInputStream)7