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();
}
}
}
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();
}
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();
}
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();
}
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();
}
}
Aggregations