Skip to content

Commit

Permalink
Feature/copy drawings (#1472)
Browse files Browse the repository at this point in the history
* copyDrawings progress

* CopyCharts are working now...

* Copy drawings

* copy control vml

* copy drawing controls progress

* Copy slicers & fixing copy issues.

* Fixed issues with copying drawings

* renamed some variables

* Refactor copy drawings code

* copy drawing control

* Groupshape copy progress.

* fixed copy slicer issue

* fixed smaller issues with slicer copy

* Fixed settings new name to copied drawings and tests

* Pivot table slicer progress

* Fixed slicer issues.

* Copy drawings on ranges
  • Loading branch information
AdrianEPPlus committed Jun 10, 2024
1 parent 4ece685 commit deda8f0
Show file tree
Hide file tree
Showing 13 changed files with 1,329 additions and 514 deletions.
22 changes: 22 additions & 0 deletions src/EPPlus/Core/RangeCopyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using OfficeOpenXml.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using static OfficeOpenXml.ExcelAddressBase;
Expand Down Expand Up @@ -94,10 +95,31 @@ internal void Copy()
CopyMergedCells(copiedMergedCells);
}

if (EnumUtil.HasNotFlag(_copyOptions, ExcelRangeCopyOptionFlags.ExcludeDrawings))
{
CopyDrawings();
}

CopyFullColumn();
CopyFullRow();
}

private void CopyDrawings()
{
foreach(var drawing in _sourceRange._worksheet.Drawings.ToList())
{
var drawingRange = new ExcelAddress(drawing.From.Row+1, drawing.From.Column+1, drawing.To.Row+1, drawing.To.Column + 1);
if (_sourceRange.Intersect(drawingRange) != null )
{
var row = drawingRange._fromRow - _sourceRange._fromRow;
row = _destination._fromRow + row - 1;
var col = drawingRange._fromCol - _sourceRange._fromCol;
col = _destination._fromCol + col - 1;
drawing.Copy(_destination.Worksheet, row, col);
}
}
}

private void CopyDataValidations()
{
foreach (var idv in _sourceRange._worksheet.DataValidations)
Expand Down
322 changes: 172 additions & 150 deletions src/EPPlus/Core/Worksheet/WorksheetCopyHelper.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/EPPlus/Drawing/Chart/ExcelChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ internal static ExcelChart CreateChartFromXml(ExcelDrawings drawings, XmlNode no
var subChart = GetChart(n, null, null, null, null, null, topChart, parent);
if (subChart != null)
{
topChart.PlotArea.ChartTypes.Add(subChart);
topChart.PlotArea.ChartTypes.Add(subChart);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/EPPlus/Drawing/Controls/ExcelControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public abstract class ExcelControl : ExcelDrawing
_control = new ControlInternal(NameSpaceManager, ctrlNode.FirstChild);
_ctrlProp = XmlHelperFactory.Create(NameSpaceManager, ControlPropertiesXml.DocumentElement);
}
private string GetControlStartWorksheetXml(string relId)

internal string GetControlStartWorksheetXml(string relId)
{
var sb = new StringBuilder();

Expand Down
17 changes: 8 additions & 9 deletions src/EPPlus/Drawing/Controls/ExcelControlWithText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Required Notice: Copyright (C) EPPlus Software AB.
This software is licensed under PolyForm Noncommercial License 1.0.0
and may only be used for noncommercial purposes
https://polyformproject.org/licenses/noncommercial/1.0.0/
https://polyformproject.org/licenses/noncommercial/1.0.0/
A commercial license to use this software can be purchased at https://epplussoftware.com
*************************************************************************************************
*************************************************************************************************
Date Author Change
*************************************************************************************************
*************************************************************************************************
11/24/2020 EPPlus Software AB Controls
*************************************************************************************************/
*************************************************************************************************/
using OfficeOpenXml.Packaging;
using OfficeOpenXml.Style;
using System;
Expand All @@ -33,7 +33,7 @@ public abstract class ExcelControlWithText : ExcelControl
InitPaths();
}

internal ExcelControlWithText(ExcelDrawings drawings, XmlElement drawNode, string name, ExcelGroupShape parent=null) :
internal ExcelControlWithText(ExcelDrawings drawings, XmlElement drawNode, string name, ExcelGroupShape parent = null) :
base(drawings, drawNode, name, parent)
{
InitPaths();
Expand All @@ -53,7 +53,6 @@ private void InitPaths()
_textBodyPath = string.Format(_textBodyPath, "xdr:sp/");
}
}

/// <summary>
/// Text inside the shape
/// </summary>
Expand All @@ -65,7 +64,7 @@ public string Text
}
set
{
if(RichText.Count==1)
if (RichText.Count == 1)
{
RichText[0].Text = value;
}
Expand Down Expand Up @@ -124,4 +123,4 @@ public ExcelTextBody TextBody
}
}
}
}
}
Loading

0 comments on commit deda8f0

Please sign in to comment.