public void Create() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet)wb.CreateSheet(); XSSFDrawing drawing = (XSSFDrawing)sheet.CreateDrawingPatriarch(); byte[] jpegData = Encoding.UTF8.GetBytes("test jpeg data"); IList pictures = wb.GetAllPictures(); Assert.AreEqual(0, pictures.Count); int jpegIdx = wb.AddPicture(jpegData, PictureType.JPEG); Assert.AreEqual(1, pictures.Count); Assert.AreEqual("jpeg", ((XSSFPictureData)pictures[jpegIdx]).SuggestFileExtension()); Assert.IsTrue(Arrays.Equals(jpegData, ((XSSFPictureData)pictures[jpegIdx]).Data)); XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30); Assert.AreEqual(AnchorType.MoveAndResize, (AnchorType)anchor.AnchorType); anchor.AnchorType = AnchorType.DontMoveAndResize; Assert.AreEqual(AnchorType.DontMoveAndResize, (AnchorType)anchor.AnchorType); XSSFPicture shape = (XSSFPicture)drawing.CreatePicture(anchor, jpegIdx); Assert.IsTrue(anchor.Equals(shape.GetAnchor())); Assert.IsNotNull(shape.PictureData); Assert.IsTrue(Arrays.Equals(jpegData, shape.PictureData.Data)); CT_TwoCellAnchor ctShapeHolder = (CT_TwoCellAnchor)drawing.GetCTDrawing().CellAnchors[0]; // STEditAs.ABSOLUTE corresponds to ClientAnchor.DONT_MOVE_AND_RESIZE Assert.AreEqual(ST_EditAs.absolute, ctShapeHolder.editAs); }
/** * Create and Initialize a CT_TwoCellAnchor that anchors a shape against top-left and bottom-right cells. * * @return a new CT_TwoCellAnchor */ private CT_TwoCellAnchor CreateTwoCellAnchor(IClientAnchor anchor) { CT_TwoCellAnchor ctAnchor = drawing.AddNewTwoCellAnchor(); XSSFClientAnchor xssfanchor = (XSSFClientAnchor)anchor; ctAnchor.from = (xssfanchor.From); ctAnchor.to = (xssfanchor.To); ctAnchor.AddNewClientData(); xssfanchor.To = ctAnchor.to; xssfanchor.From = ctAnchor.from; ST_EditAs aditAs; switch (anchor.AnchorType) { case AnchorType.DontMoveAndResize: aditAs = ST_EditAs.absolute; break; case AnchorType.MoveAndResize: aditAs = ST_EditAs.twoCell; break; case AnchorType.MoveDontResize: aditAs = ST_EditAs.oneCell; break; default: aditAs = ST_EditAs.oneCell; break; } ctAnchor.editAs = aditAs; ctAnchor.editAsSpecified = true; return(ctAnchor); }
/** * Create and Initialize a CT_TwoCellAnchor that anchors a shape against top-left and bottom-right cells. * * @return a new CT_TwoCellAnchor */ private CT_TwoCellAnchor CreateTwoCellAnchor(IClientAnchor anchor) { CT_TwoCellAnchor ctAnchor = drawing.AddNewTwoCellAnchor(); XSSFClientAnchor xssfanchor = (XSSFClientAnchor)anchor; ctAnchor.from = (xssfanchor.GetFrom()); ctAnchor.to = (xssfanchor.GetTo()); ctAnchor.AddNewClientData(); xssfanchor.SetTo(ctAnchor.to); xssfanchor.SetFrom(ctAnchor.from); ST_EditAs aditAs; switch (anchor.AnchorType) { case (int)AnchorType.DONT_MOVE_AND_RESIZE: aditAs = ST_EditAs.absolute; break; case (int)AnchorType.MOVE_AND_RESIZE: aditAs = ST_EditAs.twoCell; break; case (int)AnchorType.MOVE_DONT_RESIZE: aditAs = ST_EditAs.oneCell; break; default: aditAs = ST_EditAs.oneCell; break; } ctAnchor.editAs = aditAs; ctAnchor.editAsSpecified = true; return(ctAnchor); }
protected XMLShapeModel(PartManager manager, WsDrPart part, AnchorModel startAnchor, AnchorModel endAnchor) { Manager = manager; TwoCellAnchor = new CT_TwoCellAnchor(); CT_Marker from = new CT_Marker { Col = startAnchor.Column, ColOff = "0", Row = startAnchor.Row, RowOff = "0" }; CT_Marker to = new CT_Marker { Col = endAnchor.Column, ColOff = "0", Row = endAnchor.Row, RowOff = "0" }; TwoCellAnchor.From = from; TwoCellAnchor.To = to; ((CT_Drawing)part.Root).TwoCellAnchor.Add(TwoCellAnchor); _startPosition = startAnchor; _endPosition = endAnchor; }
private CT_TwoCellAnchor CreateTwoCellAnchor(IClientAnchor anchor) { CT_TwoCellAnchor ctTwoCellAnchor = this.drawing.AddNewTwoCellAnchor(); XSSFClientAnchor xssfClientAnchor = (XSSFClientAnchor)anchor; ctTwoCellAnchor.from = xssfClientAnchor.GetFrom(); ctTwoCellAnchor.to = xssfClientAnchor.GetTo(); ctTwoCellAnchor.AddNewClientData(); xssfClientAnchor.SetTo(ctTwoCellAnchor.to); xssfClientAnchor.SetFrom(ctTwoCellAnchor.from); NPOI.OpenXmlFormats.Dml.Spreadsheet.ST_EditAs stEditAs; switch (anchor.AnchorType) { case 0: stEditAs = NPOI.OpenXmlFormats.Dml.Spreadsheet.ST_EditAs.twoCell; break; case 2: stEditAs = NPOI.OpenXmlFormats.Dml.Spreadsheet.ST_EditAs.oneCell; break; case 3: stEditAs = NPOI.OpenXmlFormats.Dml.Spreadsheet.ST_EditAs.absolute; break; default: stEditAs = NPOI.OpenXmlFormats.Dml.Spreadsheet.ST_EditAs.oneCell; break; } ctTwoCellAnchor.editAs = stEditAs; ctTwoCellAnchor.editAsSpecified = true; return(ctTwoCellAnchor); }
/** * 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 XSSFShapeGroup CreateGroup(XSSFClientAnchor anchor) { CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor); CT_GroupShape ctGroup = ctAnchor.AddNewGrpSp(); ctGroup.Set(XSSFShapeGroup.Prototype()); XSSFShapeGroup shape = new XSSFShapeGroup(this, ctGroup); shape.anchor = anchor; return(shape); }
/** * 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 XSSFConnector CreateConnector(XSSFClientAnchor anchor) { CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor); CT_Connector ctShape = ctAnchor.AddNewCxnSp(); ctShape.Set(XSSFConnector.Prototype()); XSSFConnector shape = new XSSFConnector(this, ctShape); shape.anchor = anchor; return(shape); }
/** * 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(); CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor); CT_Shape ctShape = ctAnchor.AddNewSp(); ctShape.Set(XSSFSimpleShape.Prototype()); ctShape.nvSpPr.cNvPr.id = (uint)(shapeId); XSSFSimpleShape shape = new XSSFSimpleShape(this, ctShape); shape.anchor = anchor; return(shape); }
/** * 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 ITextbox CreateTextbox(IClientAnchor anchor) { long shapeId = newShapeId(); CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor); CT_Shape ctShape = ctAnchor.AddNewSp(); ctShape.Set(XSSFSimpleShape.Prototype()); ctShape.nvSpPr.cNvPr.id = (uint)shapeId; XSSFTextBox shape = new XSSFTextBox(this, ctShape); shape.anchor = (XSSFClientAnchor)anchor; return(shape); }
/** * 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) { CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor); CT_GraphicalObjectFrame ctGraphicFrame = ctAnchor.AddNewGraphicFrame(); ctGraphicFrame.Set(XSSFGraphicFrame.Prototype()); long frameId = numOfGraphicFrames++; XSSFGraphicFrame graphicFrame = new XSSFGraphicFrame(this, ctGraphicFrame); graphicFrame.Anchor = anchor; graphicFrame.Id = frameId; graphicFrame.Name = "Diagramm" + frameId; return(graphicFrame); }
/** * Creates a picture. * * @param anchor the client anchor describes how this picture is attached to the sheet. * @param pictureIndex the index of the picture in the workbook collection of pictures, * {@link NPOI.xssf.usermodel.XSSFWorkbook#getAllPictures()} . * * @return the newly Created picture shape. */ public IPicture CreatePicture(XSSFClientAnchor anchor, int pictureIndex) { PackageRelationship rel = AddPictureReference(pictureIndex); long shapeId = newShapeId(); CT_TwoCellAnchor ctAnchor = CreateTwoCellAnchor(anchor); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_Picture ctShape = ctAnchor.AddNewPic(); ctShape.Set(XSSFPicture.Prototype()); ctShape.nvPicPr.cNvPr.id = (uint)shapeId; XSSFPicture shape = new XSSFPicture(this, ctShape); shape.anchor = anchor; shape.SetPictureReference(rel); return(shape); }