Search in sources :

Example 1 with CTTwoCellAnchor

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor in project poi by apache.

the class XSSFDrawing method createTextbox.

/**
     * Constructs a textbox under the drawing.
     *
     * @param anchor    the client anchor describes how this group is attached
     *                  to the sheet.
     * @return      the newly created textbox.
     */
public XSSFTextBox createTextbox(XSSFClientAnchor anchor) {
    long shapeId = newShapeId();
    CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
    CTShape ctShape = ctAnchor.addNewSp();
    ctShape.set(XSSFSimpleShape.prototype());
    ctShape.getNvSpPr().getCNvPr().setId(shapeId);
    XSSFTextBox shape = new XSSFTextBox(this, ctShape);
    shape.anchor = anchor;
    return shape;
}
Also used : CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)

Example 2 with CTTwoCellAnchor

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor in project poi by apache.

the class XSSFDrawing method createGraphicFrame.

/**
     * Creates a new graphic frame.
     *
     * @param anchor    the client anchor describes how this frame is attached
     *                  to the sheet
     * @return  the newly created graphic frame
     */
private XSSFGraphicFrame createGraphicFrame(XSSFClientAnchor anchor) {
    CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
    CTGraphicalObjectFrame ctGraphicFrame = ctAnchor.addNewGraphicFrame();
    ctGraphicFrame.set(XSSFGraphicFrame.prototype());
    ctGraphicFrame.setXfrm(createXfrm(anchor));
    long frameId = numOfGraphicFrames++;
    XSSFGraphicFrame graphicFrame = new XSSFGraphicFrame(this, ctGraphicFrame);
    graphicFrame.setAnchor(anchor);
    graphicFrame.setId(frameId);
    graphicFrame.setName("Diagramm" + frameId);
    return graphicFrame;
}
Also used : CTGraphicalObjectFrame(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)

Example 3 with CTTwoCellAnchor

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor in project poi by apache.

the class XSSFDrawing method getAnchorFromParent.

private XSSFAnchor getAnchorFromParent(XmlObject obj) {
    XSSFAnchor anchor = null;
    XmlObject parentXbean = null;
    XmlCursor cursor = obj.newCursor();
    if (cursor.toParent()) {
        parentXbean = cursor.getObject();
    }
    cursor.dispose();
    if (parentXbean != null) {
        if (parentXbean instanceof CTTwoCellAnchor) {
            CTTwoCellAnchor ct = (CTTwoCellAnchor) parentXbean;
            anchor = new XSSFClientAnchor(ct.getFrom(), ct.getTo());
        } else if (parentXbean instanceof CTOneCellAnchor) {
            CTOneCellAnchor ct = (CTOneCellAnchor) parentXbean;
            anchor = new XSSFClientAnchor(ct.getFrom(), CTMarker.Factory.newInstance());
        }
    }
    return anchor;
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor) CTOneCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTOneCellAnchor) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 4 with CTTwoCellAnchor

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor in project poi by apache.

the class TestXSSFPicture method create.

@Test
public void create() throws IOException {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet();
    XSSFDrawing drawing = sheet.createDrawingPatriarch();
    byte[] jpegData = "test jpeg data".getBytes(LocaleUtil.CHARSET_1252);
    List<XSSFPictureData> pictures = wb.getAllPictures();
    assertEquals(0, pictures.size());
    int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
    assertEquals(1, pictures.size());
    assertEquals("jpeg", pictures.get(jpegIdx).suggestFileExtension());
    assertArrayEquals(jpegData, pictures.get(jpegIdx).getData());
    XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
    assertEquals(AnchorType.MOVE_AND_RESIZE, anchor.getAnchorType());
    anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);
    assertEquals(AnchorType.DONT_MOVE_AND_RESIZE, anchor.getAnchorType());
    XSSFPicture shape = drawing.createPicture(anchor, jpegIdx);
    assertTrue(anchor.equals(shape.getAnchor()));
    assertNotNull(shape.getPictureData());
    assertArrayEquals(jpegData, shape.getPictureData().getData());
    CTTwoCellAnchor ctShapeHolder = drawing.getCTDrawing().getTwoCellAnchorArray(0);
    // STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE
    assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs());
    wb.close();
}
Also used : CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor) Test(org.junit.Test)

Example 5 with CTTwoCellAnchor

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor in project poi by apache.

the class XSSFDrawing method createSimpleShape.

/**
     * Creates a simple shape.  This includes such shapes as lines, rectangles,
     * and ovals.
     *
     * @param anchor    the client anchor describes how this group is attached
     *                  to the sheet.
     * @return  the newly created shape.
     */
public XSSFSimpleShape createSimpleShape(XSSFClientAnchor anchor) {
    long shapeId = newShapeId();
    CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
    CTShape ctShape = ctAnchor.addNewSp();
    ctShape.set(XSSFSimpleShape.prototype());
    ctShape.getNvSpPr().getCNvPr().setId(shapeId);
    ctShape.getSpPr().setXfrm(createXfrm(anchor));
    XSSFSimpleShape shape = new XSSFSimpleShape(this, ctShape);
    shape.anchor = anchor;
    return shape;
}
Also used : CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)

Aggregations

CTTwoCellAnchor (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)10 CTShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape)3 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 QName (javax.xml.namespace.QName)1 POIXMLException (org.apache.poi.POIXMLException)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)1 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)1 XmlObject (org.apache.xmlbeans.XmlObject)1 Test (org.junit.Test)1 CTBlipFillProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties)1 CTGroupTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D)1 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)1 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)1 CTConnector (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector)1 CTGraphicalObjectFrame (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame)1 CTGroupShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape)1 CTOneCellAnchor (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTOneCellAnchor)1 CTPicture (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture)1