internal ExcelShape(ExcelDrawings drawings, XmlNode node, eShapeStyle style) : base(drawings, node, "xdr:sp", "xdr:nvSpPr/xdr:cNvPr") { XmlElement shapeNode = CreateShapeNode(); shapeNode.InnerXml = ShapeStartXml(); node.AppendChild(shapeNode.OwnerDocument.CreateElement("xdr", "clientData", ExcelPackage.schemaSheetDrawings)); Style = style; }
internal ExcelShape(ExcelDrawings drawings, XmlNode node, eShapeStyle style) : base(drawings, node, "xdr:sp/xdr:nvSpPr/xdr:cNvPr/@name") { init(); XmlElement shapeNode = node.OwnerDocument.CreateElement("xdr", "sp", ExcelPackage.schemaSheetDrawings); shapeNode.SetAttribute("macro", ""); shapeNode.SetAttribute("textlink", ""); node.AppendChild(shapeNode); shapeNode.InnerXml = ShapeStartXml(); node.AppendChild(shapeNode.OwnerDocument.CreateElement("xdr", "clientData", ExcelPackage.schemaSheetDrawings)); }
/// <summary> /// Add a new shape to the worksheet. /// </summary> /// <param name="name">The name of the shape.</param> /// <param name="style">The style of the shape.</param> /// <returns>Returns the newly created <see cref="ExcelShape"/>.</returns> public ExcelShape AddShape(string name, eShapeStyle style) { if (this.Worksheet is ExcelChartsheet && this._drawings.Count > 0) { throw new InvalidOperationException("Chart worksheets can't have more than one drawing"); } XmlElement drawNode = this.CreateDrawingXml(); ExcelShape shape = new ExcelShape(this, drawNode, style); shape.Name = name; shape.Style = style; this._drawings.Add(shape); return(shape); }
/// <summary> /// Add a new shape to the worksheet /// </summary> /// <param name="Name">Name</param> /// <param name="Style">Shape style</param> /// <returns>The shape object</returns> public ExcelShape AddShape(string Name, eShapeStyle Style) { if (_drawingNames.ContainsKey(Name.ToLower())) { throw new Exception("Name already exists in the drawings collection"); } XmlElement drawNode = CreateDrawingXml(); ExcelShape shape = new ExcelShape(this, drawNode, Style); shape.Name = Name; shape.Style = Style; _drawings.Add(shape); _drawingNames.Add(Name.ToLower(), _drawings.Count - 1); return(shape); }
/// <summary> /// Adds a new shape to the worksheet /// </summary> /// <param name="Name">Name</param> /// <param name="Style">Shape style</param> /// <returns>The shape object</returns> public ExcelShape AddShape(string Name, eShapeStyle Style) { if (Worksheet is ExcelChartsheet && _drawings.Count > 0) { throw new InvalidOperationException("Chart worksheets can't have more than one drawing"); } if (_drawingNames.ContainsKey(Name)) { throw new Exception("Name already exists in the drawings collection"); } XmlElement drawNode = CreateDrawingXml(); ExcelShape shape = new ExcelShape(this, drawNode, Style); shape.Name = Name; _drawings.Add(shape); _drawingNames.Add(Name, _drawings.Count - 1); return(shape); }
/// <summary> /// Add a new shape to the worksheet /// </summary> /// <param name="Name">Name</param> /// <param name="Style">Shape style</param> /// <returns>The shape object</returns> public ExcelShape AddShape(string Name, eShapeStyle Style) { if (_drawingNames.ContainsKey(Name.ToLower())) { throw new Exception("Name already exist in the drawings collection"); } XmlElement drawNode = CreateDrawingXml(); ExcelShape shape = new ExcelShape(this, drawNode, Style); shape.Name = Name; shape.Style = Style; _drawings.Add(shape); _drawingNames.Add(Name.ToLower(), _drawings.Count - 1); return shape; }
/// <summary> /// Adds the custom shape. /// </summary> /// <param name="ws">Worksheet</param> /// <param name="colIndex">Column Index</param> /// <param name="rowIndex">Row Index</param> /// <param name="shapeStyle">Shape style</param> /// <param name="text">Text for the shape</param> private static void AddCustomShape(ExcelWorksheet ws, int colIndex, int rowIndex, eShapeStyle shapeStyle, string text) { ExcelShape shape = ws.Drawings.AddShape("cs" + rowIndex.ToString() + colIndex.ToString(), shapeStyle); shape.From.Column = colIndex; shape.From.Row = rowIndex; shape.From.ColumnOff = Pixel2MTU(5); shape.SetSize(100, 100); shape.RichText.Add(text); }
/// <summary> /// Adding custom shape or object in specifed cell of specified excel sheet /// </summary> /// <param name="oSheet">The ExcelWorksheet object</param> /// <param name="rowIndex">The row number of the cell where the object will put</param> /// <param name="colIndex">The column number of the cell where the object will put</param> /// <param name="shapeStyle">The style of the shape of the object</param> /// <param name="text">Text inside the object</param> private void AddCustomObject(ExcelWorksheet oSheet, int rowIndex, int colIndex, eShapeStyle shapeStyle, string text) { ExcelShape excelShape = oSheet.Drawings.AddShape("Custom Object", shapeStyle); excelShape.From.Column = colIndex; excelShape.From.Row = rowIndex; excelShape.SetSize(100, 100); // 5x5 px space for better alignment excelShape.From.RowOff = Pixel2MTU(5); excelShape.From.ColumnOff = Pixel2MTU(5); // Adding text into the shape excelShape.RichText.Add(text); }
/// <summary> /// Addre Custom Shape with text to WorkSheet /// </summary> /// <param name="excelWorksheet"></param> /// <param name="colIndex"></param> /// <param name="rowIndex"></param> /// <param name="shapeStyle">eShapeStyle</param> /// <param name="text">Shape Content inside</param> /// <param name="shapeSize">Size of Shape</param> /// <returns></returns> public ExcelWorksheet AddCustomShape(ExcelWorksheet excelWorksheet, int colIndex, int rowIndex, eShapeStyle shapeStyle, string text, Size shapeSize) { ExcelShape shape = excelWorksheet.Drawings.AddShape("cs" + rowIndex.ToString() + colIndex.ToString(), shapeStyle); shape.From.Column = colIndex; shape.From.Row = rowIndex; shape.From.ColumnOff = Pixel2MTU(5); shape.SetSize(shapeSize.Width, shapeSize.Height); shape.RichText.Add(text); return(excelWorksheet); }