2013-08-22 3 views
3

EPPlus 라이브러리를 사용하여 Excel 워크 시트에 도형의 복사/복제본을 만들 수 있습니까?EPPlus를 사용하여 Excel 셰이프를 복사/복제 하시겠습니까?

은 내가

var shapeExisting = ws.Drawings["ShapeName"]; 

및 그러나

var shapeNew = ws.Drawings.AddShape("NewName", eShapeStyle.RtTriangle); 

과 함께 만든 새 모양 (ws는 워크 시트 개체 인)와 기존 개체를 얻을 수있어, 나는 수 없어요 복제 할 방법을 찾으려면 shapeExisting. 나는 더 나은 해결책을 찾을 때까지 그래서 내장 기능이 없다처럼

답변

1

가 보인다, 나는 ExcelShape.csEPPlus\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; 
} 

이 생성자에 다음과 같은 방법을 추가 :

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); 
} 
관련 문제