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