È ansible creare una copia / clone di una forma in un foglio di lavoro di Excel utilizzando la libreria EPPlus?
So che posso get un object esistente con
var shapeExisting = ws.Drawings["ShapeName"];
( ws
è l'object foglio di lavoro)
e creare una nuova forma con
var shapeNew = ws.Drawings.AddShape("NewName", eShapeStyle.RtTriangle);
Tuttavia, non riesco a trovare un modo per clonare shapeExisting
.
Sembra che non ci sia funzionalità incorporata, quindi fino a trovare una soluzione migliore, ho aggiunto il seguente metodo a EPPlus\Drawings\ExcelDrawings.cs
public ExcelShape CloneShape(string SourceName, string TargetName) { if ( _drawingNames.ContainsKey(TargetName.ToLower())) { throw new Exception("Target name already exists in the drawings collection"); } if (!_drawingNames.ContainsKey(SourceName.ToLower())) { throw new Exception("Source shape does not exist in the drawings collection"); } ExcelShape shape = new ExcelShape(this, this._drawingsXml, (ExcelShape) this[SourceName]); shape.Name = TargetName; _drawings.Add(shape); _drawingNames.Add(TargetName.ToLower(), _drawings.Count - 1); return shape; }
e anche questo constructor in ExcelShape.cs
:
internal ExcelShape(ExcelDrawings drawings, XmlDocument DrawingsXml, ExcelShape shapeSource) : base(drawings, shapeSource._topNode.Clone(), "xdr:sp/xdr:nvSpPr/xdr:cNvPr/@name") { this.init(); XmlNode colNode = DrawingsXml.SelectSingleNode("//xdr:wsDr", NameSpaceManager); colNode.AppendChild(this._topNode); }