复制/克隆与EPPlus一个Excel形状? [英] Copy/clone an Excel shape with EPPlus?
本文介绍了复制/克隆与EPPlus一个Excel形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能在Excel工作表使用EPPlus库中创建形状的复制/克隆?
Is it possible to create a copy/clone of a shape in an Excel worksheet using the EPPlus library?
我知道我能得到一个现有对象以
I know I can get an existing object with
var shapeExisting = ws.Drawings["ShapeName"];
( WS
作为工作表对象)
和一个创建
var shapeNew = ws.Drawings.AddShape("NewName", eShapeStyle.RtTriangle);
不过,我无法找到一个方法来克隆 shapeExisting
。
推荐答案
好像没有内置的功能,所以直到我找到一个更好的解决办法,我加下面的方法 EPPlus\Drawings\ExcelDrawings.cs
Seems like there's no built-in functionality, so until I find a better solution, I added the following method to 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;
}
和也此构造在 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);
}
这篇关于复制/克隆与EPPlus一个Excel形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文