Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/copy drawings #1472

Merged
merged 18 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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