Search in sources :

Example 11 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class XWPFDocument method initFootnotes.

private void initFootnotes() throws XmlException, IOException {
    for (RelationPart rp : getRelationParts()) {
        POIXMLDocumentPart p = rp.getDocumentPart();
        String relation = rp.getRelationship().getRelationshipType();
        if (relation.equals(XWPFRelation.FOOTNOTE.getRelation())) {
            this.footnotes = (XWPFFootnotes) p;
            this.footnotes.onDocumentRead();
        } else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())) {
            EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream(), DEFAULT_XML_OPTIONS);
            for (CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteArray()) {
                endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
            }
        }
    }
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart)

Example 12 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class XWPFHeaderFooter method onDocumentRead.

@Override
protected void onDocumentRead() throws IOException {
    for (POIXMLDocumentPart poixmlDocumentPart : getRelations()) {
        if (poixmlDocumentPart instanceof XWPFPictureData) {
            XWPFPictureData xwpfPicData = (XWPFPictureData) poixmlDocumentPart;
            pictures.add(xwpfPicData);
            document.registerPackagePictureData(xwpfPicData);
        }
    }
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart)

Example 13 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class TestXSLFBugs method assertRelation.

private static void assertRelation(XSLFSlide slide, String exp, String rId) {
    POIXMLDocumentPart pd = (rId != null) ? slide.getRelationById(rId) : slide;
    assertNotNull(pd);
    assertEquals(exp, pd.getPackagePart().getPartName().getName());
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart)

Example 14 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class TestMapInfo method testMapInfoExists.

public void testMapInfoExists() {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMappings.xlsx");
    MapInfo mapInfo = null;
    SingleXmlCells singleXMLCells = null;
    for (POIXMLDocumentPart p : wb.getRelations()) {
        if (p instanceof MapInfo) {
            mapInfo = (MapInfo) p;
            CTMapInfo ctMapInfo = mapInfo.getCTMapInfo();
            assertNotNull(ctMapInfo);
            assertEquals(1, ctMapInfo.sizeOfSchemaArray());
            for (XSSFMap map : mapInfo.getAllXSSFMaps()) {
                Node xmlSchema = map.getSchema();
                assertNotNull(xmlSchema);
            }
        }
    }
    XSSFSheet sheet1 = wb.getSheetAt(0);
    for (POIXMLDocumentPart p : sheet1.getRelations()) {
        if (p instanceof SingleXmlCells) {
            singleXMLCells = (SingleXmlCells) p;
        }
    }
    assertNotNull(mapInfo);
    assertNotNull(singleXMLCells);
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) CTMapInfo(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMapInfo) XSSFMap(org.apache.poi.xssf.usermodel.XSSFMap) Node(org.w3c.dom.Node) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) CTMapInfo(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMapInfo)

Example 15 with POIXMLDocumentPart

use of org.apache.poi.POIXMLDocumentPart in project poi by apache.

the class TestXWPFDocument method testPictureHandlingComplex.

@Test
public void testPictureHandlingComplex() throws IOException, InvalidFormatException {
    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
    XWPFHeader xwpfHeader = doc.getHeaderArray(0);
    assertEquals(3, doc.getAllPictures().size());
    assertEquals(3, xwpfHeader.getAllPictures().size());
    assertEquals(5, doc.getAllPackagePictures().size());
    byte[] nature1 = XWPFTestDataSamples.getImage("nature1.jpg");
    String id = doc.addPictureData(nature1, Document.PICTURE_TYPE_JPEG);
    POIXMLDocumentPart part1 = xwpfHeader.getRelationById("rId1");
    XWPFPictureData part2 = (XWPFPictureData) doc.getRelationById(id);
    assertSame(part1, part2);
    doc.getPackage().revert();
    doc.close();
}
Also used : POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) Test(org.junit.Test)

Aggregations

POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)42 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)16 MapInfo (org.apache.poi.xssf.model.MapInfo)14 XSSFMap (org.apache.poi.xssf.usermodel.XSSFMap)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 POIXMLException (org.apache.poi.POIXMLException)9 XmlException (org.apache.xmlbeans.XmlException)7 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)3 HashMap (java.util.HashMap)3 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)2 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)2 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)2 CellReference (org.apache.poi.ss.util.CellReference)2 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)2 CTAxDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)2 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)2