Search in sources :

Example 76 with OPCPackage

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

the class XSLFMetroShape method parseShape.

/*
     * parses the metro bytes to a XSLF shape
     */
public static Shape<?, ?> parseShape(byte[] metroBytes) throws InvalidFormatException, IOException, XmlException {
    PackagePartName shapePN = PackagingURIHelper.createPartName("/drs/shapexml.xml");
    OPCPackage pkg = null;
    try {
        pkg = OPCPackage.open(new ByteArrayInputStream(metroBytes));
        PackagePart shapePart = pkg.getPart(shapePN);
        CTGroupShape gs = CTGroupShape.Factory.parse(shapePart.getInputStream(), DEFAULT_XML_OPTIONS);
        XSLFGroupShape xgs = new XSLFGroupShape(gs, null);
        return xgs.getShapes().get(0);
    } finally {
        if (pkg != null) {
            pkg.close();
        }
    }
}
Also used : PackagePartName(org.apache.poi.openxml4j.opc.PackagePartName) ByteArrayInputStream(java.io.ByteArrayInputStream) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Example 77 with OPCPackage

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

the class TestXMLPropertiesTextExtractor method testCustom.

public void testCustom() throws Exception {
    OPCPackage pkg = OPCPackage.open(_ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm"));
    XSSFWorkbook wb = new XSSFWorkbook(pkg);
    POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(wb);
    ext.getText();
    // Now check
    String text = ext.getText();
    String cText = ext.getCustomPropertiesText();
    assertContains(text, "description = another value");
    assertContains(cText, "description = another value");
    ext.close();
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Example 78 with OPCPackage

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

the class TestOOXMLLister method testWithPrintStream.

@Test
public void testWithPrintStream() throws IOException, InvalidFormatException {
    File file = XSSFTestDataSamples.getSampleFile("Formatting.xlsx");
    PrintStream nullStream = new PrintStream(new NullOutputStream(), true, "UTF-8");
    OPCPackage opc = OPCPackage.open(file.getAbsolutePath(), PackageAccess.READ);
    OOXMLLister lister = new OOXMLLister(opc, nullStream);
    lister.displayParts();
    lister.displayRelations();
    lister.close();
    opc.close();
    nullStream.close();
}
Also used : PrintStream(java.io.PrintStream) File(java.io.File) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) NullOutputStream(org.apache.poi.util.NullOutputStream) Test(org.junit.Test)

Example 79 with OPCPackage

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

the class TestXMLPropertiesTextExtractor method testExtended.

public void testExtended() throws Exception {
    OPCPackage pkg = OPCPackage.open(_ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm"));
    XSSFWorkbook wb = new XSSFWorkbook(pkg);
    POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(wb);
    ext.getText();
    // Now check
    String text = ext.getText();
    String eText = ext.getExtendedPropertiesText();
    assertContains(text, "Application = Microsoft Excel");
    assertContains(text, "Company = Mera");
    assertContains(eText, "Application = Microsoft Excel");
    assertContains(eText, "Company = Mera");
    ext.close();
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Example 80 with OPCPackage

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

the class TestPOIXMLDocument method testRelationOrder.

@Test
public void testRelationOrder() throws Exception {
    POIDataSamples pds = POIDataSamples.getDocumentInstance();
    @SuppressWarnings("resource") OPCPackage pkg = PackageHelper.open(pds.openResourceAsStream("WordWithAttachments.docx"));
    OPCParser doc = new OPCParser(pkg);
    try {
        doc.parse(new TestFactory());
        for (POIXMLDocumentPart rel : doc.getRelations()) {
            //TODO finish me
            assertNotNull(rel);
        }
    } finally {
        doc.close();
    }
}
Also used : OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

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