将带有EPPlus的Excel形状复制/克隆到其他工作表
本文关键字:其他 工作 复制 EPPlus Excel | 更新日期: 2023-09-27 17:52:48
是否可以使用EPPlus库将形状复制/克隆到其他 Excel工作表?
在这里显示的相同Excel工作表中已经有一个解决方案:用EPPlus复制/克隆Excel形状?
但我需要将其复制到其他工作表的可能性(从模板到目的地)。有人知道解决这个问题的方法吗?
实际上我找到了一个解决这个问题的方法。我将这段代码添加到exceldrawing .cs文件:
/// <summary>
/// Add a new shape to the worksheet
/// </summary>
/// <param name="Name">Name</param>
/// <param name="Source">Source shape</param>
/// <returns>The shape object</returns>
public ExcelShape AddShape(string Name, ExcelShape Source)
{
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();
drawNode.InnerXml = Source.TopNode.InnerXml;
ExcelShape shape = new ExcelShape(this, drawNode);
shape.Name = Name;
shape.Style = Source.Style;
_drawings.Add(shape);
_drawingNames.Add(Name, _drawings.Count - 1);
return shape;
}