Search in sources :

Example 6 with CTGraphicalObjectFrame

use of org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame in project poi by apache.

the class TestXSLFTable method testCreate.

@Test
public void testCreate() throws IOException {
    XMLSlideShow ppt1 = new XMLSlideShow();
    XSLFSlide slide = ppt1.createSlide();
    XSLFTable tbl = slide.createTable();
    assertNotNull(tbl.getCTTable());
    assertNotNull(tbl.getCTTable().getTblGrid());
    assertNotNull(tbl.getCTTable().getTblPr());
    assertTrue(tbl.getXmlObject() instanceof CTGraphicalObjectFrame);
    assertEquals("Table 1", tbl.getShapeName());
    assertEquals(2, tbl.getShapeId());
    assertEquals(0, tbl.getRows().size());
    assertEquals(0, tbl.getCTTable().sizeOfTrArray());
    assertEquals(0, tbl.getCTTable().getTblGrid().sizeOfGridColArray());
    assertEquals(0, tbl.getNumberOfColumns());
    assertEquals(0, tbl.getNumberOfRows());
    XSLFTableRow row0 = tbl.addRow();
    assertNotNull(row0.getXmlObject());
    assertEquals(1, tbl.getNumberOfRows());
    assertSame(row0, tbl.getRows().get(0));
    assertEquals(20.0, row0.getHeight(), 0);
    row0.setHeight(30.0);
    assertEquals(30.0, row0.getHeight(), 0);
    assertEquals(0, row0.getCells().size());
    XSLFTableCell cell0 = row0.addCell();
    assertNotNull(cell0.getXmlObject());
    // by default table cell has no borders
    CTTableCell tc = (CTTableCell) cell0.getXmlObject();
    assertTrue(tc.getTcPr().getLnB().isSetNoFill());
    assertTrue(tc.getTcPr().getLnT().isSetNoFill());
    assertTrue(tc.getTcPr().getLnL().isSetNoFill());
    assertTrue(tc.getTcPr().getLnR().isSetNoFill());
    assertSame(cell0, row0.getCells().get(0));
    assertEquals(1, tbl.getNumberOfColumns());
    assertEquals(100.0, tbl.getColumnWidth(0), 0);
    cell0.addNewTextParagraph().addNewTextRun().setText("POI");
    assertEquals("POI", cell0.getText());
    XSLFTableCell cell1 = row0.addCell();
    assertSame(cell1, row0.getCells().get(1));
    assertEquals(2, tbl.getNumberOfColumns());
    assertEquals(100.0, tbl.getColumnWidth(1), 0);
    cell1.addNewTextParagraph().addNewTextRun().setText("Apache");
    assertEquals("Apache", cell1.getText());
    for (BorderEdge edge : BorderEdge.values()) {
        assertNull(cell1.getBorderWidth(edge));
        cell1.setBorderWidth(edge, 2.0);
        assertEquals(2.0, cell1.getBorderWidth(edge), 0);
        assertNull(cell1.getBorderColor(edge));
        cell1.setBorderColor(edge, Color.yellow);
        assertEquals(Color.yellow, cell1.getBorderColor(edge));
    }
    assertEquals(VerticalAlignment.TOP, cell1.getVerticalAlignment());
    cell1.setVerticalAlignment(VerticalAlignment.MIDDLE);
    assertEquals(VerticalAlignment.MIDDLE, cell1.getVerticalAlignment());
    cell1.setVerticalAlignment(null);
    assertEquals(VerticalAlignment.TOP, cell1.getVerticalAlignment());
    XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt1);
    ppt1.close();
    slide = ppt2.getSlides().get(0);
    tbl = (XSLFTable) slide.getShapes().get(0);
    assertEquals(2, tbl.getNumberOfColumns());
    assertEquals(1, tbl.getNumberOfRows());
    assertEquals("POI", tbl.getCell(0, 0).getText());
    assertEquals("Apache", tbl.getCell(0, 1).getText());
    ppt2.close();
}
Also used : CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) CTTableCell(org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell) BorderEdge(org.apache.poi.sl.usermodel.TableCell.BorderEdge) Test(org.junit.Test)

Example 7 with CTGraphicalObjectFrame

use of org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame in project poi by apache.

the class XSLFSheet method appendContent.

/**
     * Append content to this sheet.
     *
     * @param src the source sheet
     * @return modified <code>this</code>.
     */
public XSLFSheet appendContent(XSLFSheet src) {
    CTGroupShape spTree = getSpTree();
    int numShapes = getShapes().size();
    CTGroupShape srcTree = src.getSpTree();
    for (XmlObject ch : srcTree.selectPath("*")) {
        if (ch instanceof CTShape) {
            // simple shape
            spTree.addNewSp().set(ch);
        } else if (ch instanceof CTGroupShape) {
            spTree.addNewGrpSp().set(ch);
        } else if (ch instanceof CTConnector) {
            spTree.addNewCxnSp().set(ch);
        } else if (ch instanceof CTPicture) {
            spTree.addNewPic().set(ch);
        } else if (ch instanceof CTGraphicalObjectFrame) {
            spTree.addNewGraphicFrame().set(ch);
        }
    }
    _shapes = null;
    _spTree = null;
    _drawing = null;
    _spTree = null;
    _placeholders = null;
    // recursively update each shape
    List<XSLFShape> tgtShapes = getShapes();
    List<XSLFShape> srcShapes = src.getShapes();
    for (int i = 0; i < srcShapes.size(); i++) {
        XSLFShape s1 = srcShapes.get(i);
        XSLFShape s2 = tgtShapes.get(numShapes + i);
        s2.copy(s1);
    }
    return this;
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) XmlObject(org.apache.xmlbeans.XmlObject) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Example 8 with CTGraphicalObjectFrame

use of org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame in project poi by apache.

the class XSLFCommonSlideData method getDrawingText.

public List<DrawingTextBody> getDrawingText() {
    CTGroupShape gs = data.getSpTree();
    List<DrawingTextBody> out = new ArrayList<DrawingTextBody>();
    processShape(gs, out);
    for (CTGroupShape shape : gs.getGrpSpArray()) {
        processShape(shape, out);
    }
    for (CTGraphicalObjectFrame frame : gs.getGraphicFrameArray()) {
        CTGraphicalObjectData data = frame.getGraphic().getGraphicData();
        XmlCursor c = data.newCursor();
        c.selectPath("declare namespace pic='" + CTTable.type.getName().getNamespaceURI() + "' .//pic:tbl");
        while (c.toNextSelection()) {
            XmlObject o = c.getObject();
            if (o instanceof XmlAnyTypeImpl) {
                // Pesky XmlBeans bug - see Bugzilla #49934
                try {
                    o = CTTable.Factory.parse(o.toString(), DEFAULT_XML_OPTIONS);
                } catch (XmlException e) {
                    throw new POIXMLException(e);
                }
            }
            if (o instanceof CTTable) {
                DrawingTable table = new DrawingTable((CTTable) o);
                for (DrawingTableRow row : table.getRows()) {
                    for (DrawingTableCell cell : row.getCells()) {
                        DrawingTextBody textBody = cell.getTextBody();
                        out.add(textBody);
                    }
                }
            }
        }
        c.dispose();
    }
    return out;
}
Also used : CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) ArrayList(java.util.ArrayList) POIXMLException(org.apache.poi.POIXMLException) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape) XmlCursor(org.apache.xmlbeans.XmlCursor) CTGraphicalObjectData(org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData) XmlException(org.apache.xmlbeans.XmlException) CTTable(org.openxmlformats.schemas.drawingml.x2006.main.CTTable) XmlAnyTypeImpl(org.apache.xmlbeans.impl.values.XmlAnyTypeImpl) XmlObject(org.apache.xmlbeans.XmlObject)

Example 9 with CTGraphicalObjectFrame

use of org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame in project poi by apache.

the class XSLFGraphicFrame method setAnchor.

@Override
public void setAnchor(Rectangle2D anchor) {
    CTTransform2D xfrm = ((CTGraphicalObjectFrame) getXmlObject()).getXfrm();
    CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
    long x = Units.toEMU(anchor.getX());
    long y = Units.toEMU(anchor.getY());
    off.setX(x);
    off.setY(y);
    CTPositiveSize2D ext = xfrm.isSetExt() ? xfrm.getExt() : xfrm.addNewExt();
    long cx = Units.toEMU(anchor.getWidth());
    long cy = Units.toEMU(anchor.getHeight());
    ext.setCx(cx);
    ext.setCy(cy);
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTPoint2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) CTPositiveSize2D(org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)

Example 10 with CTGraphicalObjectFrame

use of org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame in project poi by apache.

the class XSLFGroupShape method removeShape.

/**
     * Remove the specified shape from this group
     */
@Override
public boolean removeShape(XSLFShape xShape) {
    XmlObject obj = xShape.getXmlObject();
    CTGroupShape grpSp = (CTGroupShape) getXmlObject();
    if (obj instanceof CTShape) {
        grpSp.getSpList().remove(obj);
    } else if (obj instanceof CTGroupShape) {
        grpSp.getGrpSpList().remove(obj);
    } else if (obj instanceof CTConnector) {
        grpSp.getCxnSpList().remove(obj);
    } else if (obj instanceof CTGraphicalObjectFrame) {
        grpSp.getGraphicFrameList().remove(obj);
    } else if (obj instanceof CTPicture) {
        XSLFPictureShape ps = (XSLFPictureShape) xShape;
        XSLFSheet sh = getSheet();
        if (sh != null) {
            sh.removePictureRelation(ps);
        }
        grpSp.getPicList().remove(obj);
    } else {
        throw new IllegalArgumentException("Unsupported shape: " + xShape);
    }
    return _shapes.remove(xShape);
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) XmlObject(org.apache.xmlbeans.XmlObject) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Aggregations

CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)10 XmlObject (org.apache.xmlbeans.XmlObject)5 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)5 CTConnector (org.openxmlformats.schemas.presentationml.x2006.main.CTConnector)4 CTPicture (org.openxmlformats.schemas.presentationml.x2006.main.CTPicture)4 CTShape (org.openxmlformats.schemas.presentationml.x2006.main.CTShape)4 ArrayList (java.util.ArrayList)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 CTGraphicalObjectData (org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData)2 CTPoint2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D)2 CTPositiveSize2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D)2 CTTable (org.openxmlformats.schemas.drawingml.x2006.main.CTTable)2 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)2 Rectangle2D (java.awt.geom.Rectangle2D)1 QName (javax.xml.namespace.QName)1 POIXMLException (org.apache.poi.POIXMLException)1 BorderEdge (org.apache.poi.sl.usermodel.TableCell.BorderEdge)1 XmlException (org.apache.xmlbeans.XmlException)1 XmlAnyTypeImpl (org.apache.xmlbeans.impl.values.XmlAnyTypeImpl)1 Test (org.junit.Test)1