import org.apache.poi.xssf.model.CommentsTable;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape;
* @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;
{
PackageRelationship rel = addPictureReference(pictureIndex);
+ long shapeId = newShapeId();
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
CTPicture ctShape = ctAnchor.addNewPic();
ctShape.set(XSSFPicture.prototype());
+ ctShape.getNvPicPr().getCNvPr().setId(shapeId);
+
XSSFPicture shape = new XSSFPicture(this, ctShape);
shape.anchor = anchor;
shape.setPictureReference(rel);
*/
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);
XSSFSimpleShape shape = new XSSFSimpleShape(this, ctShape);
shape.anchor = anchor;
return shape;
ctAnchor.setEditAs(aditAs);
return ctAnchor;
}
+
+ private long newShapeId(){
+ return drawing.sizeOfTwoCellAnchorArray() + 1;
+ }
}
// STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE
assertEquals(STEditAs.ABSOLUTE, ctShapeHolder.getEditAs());
}
+
+ /**
+ * test that ShapeId in CTNonVisualDrawingProps is incremented
+ *
+ * See Bugzilla 50458
+ */
+ public void testShapeId(){
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+
+ XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
+ byte[] jpegData = "picture1".getBytes();
+ int jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
+
+ XSSFPicture shape1 = drawing.createPicture(anchor, jpegIdx);
+ assertEquals(1, shape1.getCTPicture().getNvPicPr().getCNvPr().getId());
+
+ jpegData = "picture2".getBytes();
+ jpegIdx = wb.addPicture(jpegData, XSSFWorkbook.PICTURE_TYPE_JPEG);
+ XSSFPicture shape2 = drawing.createPicture(anchor, jpegIdx);
+ assertEquals(2, shape2.getCTPicture().getNvPicPr().getCNvPr().getId());
+ }
}