internal ShapeContainer(uint spid, ShapeType shapeType, ShapeFlag shapeFlags, ClientAnchor.SPRC clientAnchorInfo, uint refIndex, string imageName, string hyperLinkName, HyperlinkType hyperLinkType) : base(15, 0u, EscherType.MSOFBTSPCONTAINER, 0u) { m_shape = new Shape(shapeType, shapeFlags, spid); m_drawingOpt = new DrawingOpt(imageName, refIndex, hyperLinkName, hyperLinkType); m_clientAnchor = new ClientAnchor(clientAnchorInfo); m_clientData = new ClientData(); }
/// <summary> /// Constructs a textbox Under the patriarch. /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <returns>the newly Created textbox.</returns> public Textbox CreateTextbox(ClientAnchor anchor) { HSSFTextbox shape = new HSSFTextbox(null, (HSSFAnchor)anchor); shape.Anchor = (HSSFAnchor)anchor; shapes.Add(shape); return(shape); }
/// <summary> /// Creates a polygon /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <returns>the newly Created shape.</returns> public HSSFPolygon CreatePolygon(ClientAnchor anchor) { HSSFPolygon shape = new HSSFPolygon(null, (HSSFAnchor)anchor); shape.Anchor = (HSSFAnchor)anchor; shapes.Add(shape); return(shape); }
/// <summary> /// Creates a picture. /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <param name="pictureIndex">Index of the picture.</param> /// <returns>the newly created shape.</returns> public NPOI.SS.UserModel.Picture CreatePicture(ClientAnchor anchor, int pictureIndex) { HSSFPicture shape = new HSSFPicture(null, (HSSFClientAnchor)anchor); shape.PictureIndex = pictureIndex; shape.Anchor = (HSSFClientAnchor)anchor; shape.Patriarch = this; shapes.Add(shape); return(shape); }
/// <summary> /// Reset the image to the original size. /// </summary> public void Resize(double scale) { HSSFClientAnchor anchor = (HSSFClientAnchor)Anchor; anchor.AnchorType = 2; ClientAnchor pref = GetPreferredSize(scale); int row2 = anchor.Row1 + (pref.Row2 - pref.Row1); int col2 = anchor.Col1 + (pref.Col2 - pref.Col1); anchor.Col2 = col2; anchor.Dx1 = 0; anchor.Dx2 = pref.Dx2; anchor.Row2 = row2; anchor.Dy1 = 0; anchor.Dy2 = pref.Dy2; }
public void TestResize() { HSSFWorkbook wb = new HSSFWorkbook(); NPOI.SS.UserModel.Sheet sh1 = wb.CreateSheet(); Drawing p1 = sh1.CreateDrawingPatriarch(); byte[] pictureData = HSSFTestDataSamples.GetTestDataFileContent("logoKarmokar4.png"); int idx1 = wb.AddPicture(pictureData, PictureType.PNG); Picture picture1 = p1.CreatePicture(new HSSFClientAnchor(), idx1); ClientAnchor anchor1 = picture1.GetPreferredSize(); //assert against what would BiffViewer print if we insert the image in xls and dump the file Assert.AreEqual(0, anchor1.Col1); Assert.AreEqual(0, anchor1.Row1); Assert.AreEqual(1, anchor1.Col2); Assert.AreEqual(9, anchor1.Row2); Assert.AreEqual(0, anchor1.Dx1); Assert.AreEqual(0, anchor1.Dy1); Assert.AreEqual(848, anchor1.Dx2); Assert.AreEqual(240, anchor1.Dy2); }
/// <summary> /// Mapping definition for embedded objects /// </summary> /// <param name="objectsSequence"></param> public void Apply(ObjectsSequence objectsSequence) { _writer.WriteStartElement(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElWsDr, Dml.SpreadsheetDrawing.Ns); _writer.WriteAttributeString("xmlns", Dml.SpreadsheetDrawing.Prefix, "", Dml.SpreadsheetDrawing.Ns); _writer.WriteAttributeString("xmlns", Dml.Prefix, "", Dml.Ns); foreach (DrawingsGroup drawingsGroup in objectsSequence.DrawingsGroup) { // TODO: currently only embedded charts are mapped. Shapes and images are not yet implemented. // The check on the type of object would have to be removed here once shapes and images are supported. // ObjectGroup objGroup = drawingsGroup.Objects.Find(p => p.ChartSheetSequence != null); if (objGroup != null) { MsoDrawing msoDrawing = drawingsGroup.MsoDrawing; // find OfficeArtClientAnchorSheet with drawing RegularContainer container = msoDrawing.rgChildRec as RegularContainer; if (container != null) { ClientAnchor clientAnchor = container.FirstDescendantWithType <ClientAnchor>(); if (clientAnchor != null) { OfficeArtClientAnchorSheet oartClientAnchor = new OfficeArtClientAnchorSheet(clientAnchor.RawData); // xdr:twoCellAnchor _writer.WriteStartElement(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElTwoCellAnchor, Dml.SpreadsheetDrawing.Ns); string editAs = "absolute"; if (oartClientAnchor.fSize && oartClientAnchor.fMove) { // Move and resize with anchor cells editAs = "twoCell"; } else if (!oartClientAnchor.fSize && oartClientAnchor.fMove) { // Move with cells but do not resize editAs = "oneCell"; } _writer.WriteAttributeString(Dml.SpreadsheetDrawing.AttrEditAs, editAs); { // xdr:from _writer.WriteStartElement(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElFrom, Dml.SpreadsheetDrawing.Ns); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElCol, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.colL.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElColOff, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.dxL.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElRow, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.rwT.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElRowOff, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.dyT.ToString()); _writer.WriteEndElement(); // xdr:from // xdr:to _writer.WriteStartElement(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElTo, Dml.SpreadsheetDrawing.Ns); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElCol, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.colR.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElColOff, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.dxR.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElRow, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.rwB.ToString()); _writer.WriteElementString(Dml.SpreadsheetDrawing.Prefix, Dml.SpreadsheetDrawing.ElRowOff, Dml.SpreadsheetDrawing.Ns, oartClientAnchor.dyB.ToString()); _writer.WriteEndElement(); // xdr:to ObjectGroup objectGroup = drawingsGroup.Objects.Find(p => p.ChartSheetSequence != null); if (objectGroup != null) { ChartSheetContentSequence chartSheetContentSequence = objectGroup.ChartSheetSequence.ChartSheetContentSequence; insertObjectChoices(chartSheetContentSequence); } } _writer.WriteEndElement(); // xdr:twoCellAnchor } } } } _writer.WriteEndElement(); _writer.WriteEndDocument(); _writer.Flush(); }
/* * 添加电子印章 * */ private void AddSeal(string sealImg, PictureType format, ClientAnchor anchor) { //add picture data to this workbook. byte[] bytes = System.IO.File.ReadAllBytes(reportTemplateFolder + sealImg); int pictureIdx = this.workbook.AddPicture(bytes, format); // Create the drawing patriarch. This is the top level container for all shapes. Drawing patriarch = this.sheet.CreateDrawingPatriarch(); //add a picture if (anchor == null) { anchor = new HSSFClientAnchor(0, 0, 0, 0, 5, 40, 50, 40); } Picture pict = patriarch.CreatePicture(anchor, pictureIdx); pict.Resize(); }
private void AddSeal(string sealImg, ClientAnchor anchor) { if (sealImg.EndsWith("jpeg", StringComparison.CurrentCultureIgnoreCase) || sealImg.EndsWith("jpg", StringComparison.CurrentCultureIgnoreCase)) { this.AddSeal(sealImg, PictureType.JPEG, anchor); } else if (sealImg.EndsWith("png", StringComparison.CurrentCultureIgnoreCase)) { this.AddSeal(sealImg, PictureType.PNG, anchor); } }
/// <summary> /// Creates a picture. /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <param name="pictureIndex">Index of the picture.</param> /// <returns>the newly created shape.</returns> public NPOI.SS.UserModel.Picture CreatePicture(ClientAnchor anchor, int pictureIndex) { HSSFPicture shape = new HSSFPicture(null, (HSSFClientAnchor)anchor); shape.PictureIndex=pictureIndex; shape.Anchor = (HSSFClientAnchor)anchor; shape.Patriarch = this; shapes.Add(shape); return shape; }
/// <summary> /// Constructs a textbox Under the patriarch. /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <returns>the newly Created textbox.</returns> public Textbox CreateTextbox(ClientAnchor anchor) { HSSFTextbox shape = new HSSFTextbox(null, (HSSFAnchor)anchor); shape.Anchor = (HSSFAnchor)anchor; shapes.Add(shape); return shape; }
/// <summary> /// Creates a polygon /// </summary> /// <param name="anchor">the client anchor describes how this Group is attached /// to the sheet.</param> /// <returns>the newly Created shape.</returns> public HSSFPolygon CreatePolygon(ClientAnchor anchor) { HSSFPolygon shape = new HSSFPolygon(null, (HSSFAnchor)anchor); shape.Anchor = (HSSFAnchor)anchor; shapes.Add(shape); return shape; }