diff --git a/src/EPPlus/Drawing/ExcelDrawings.cs b/src/EPPlus/Drawing/ExcelDrawings.cs index ea3574c24..3f200ec90 100644 --- a/src/EPPlus/Drawing/ExcelDrawings.cs +++ b/src/EPPlus/Drawing/ExcelDrawings.cs @@ -1218,10 +1218,6 @@ private void AddPicture(string Name, ExcelPicture pic) } private void ValidatePictureFile(string Name, FileInfo ImageFile) { - if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0) - { - throw new InvalidOperationException("Chart worksheets can't have more than one drawing"); - } if (ImageFile == null) { throw (new Exception("AddPicture: ImageFile can't be null")); @@ -1296,10 +1292,6 @@ public ExcelChart AddChartFromTemplate(Stream crtxStream, string name) /// The new chart public ExcelChart AddChartFromTemplate(Stream crtxStream, string name, ExcelPivotTable pivotTableSource) { - if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0) - { - throw new InvalidOperationException("Chart worksheets can't have more than one drawing"); - } CrtxTemplateHelper.LoadCrtx(crtxStream, out XmlDocument chartXml, out XmlDocument styleXml, out XmlDocument colorsXml, out ZipPackagePart themePart, "The crtx stream"); if (chartXml == null) { @@ -1401,10 +1393,6 @@ public ExcelShape AddShape(string Name, eShapeStyle Style) } internal ExcelShape AddShape(string Name, eShapeStyle Style, object container = null) { - if (Worksheet is ExcelChartsheet && _drawingsList.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"); @@ -1436,11 +1424,6 @@ internal ExcelShape AddShape(string Name, eShapeStyle Style, object container = /// The slicer drawing public ExcelTableSlicer AddTableSlicer(ExcelTableColumn TableColumn) { - if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0) - { - throw new InvalidOperationException("Chart worksheets can't have more than one drawing"); - } - if (TableColumn.Table.AutoFilter.Columns[TableColumn.Position] == null) { TableColumn.Table.AutoFilter.Columns.AddValueFilterColumn(TableColumn.Position); @@ -1464,10 +1447,6 @@ public ExcelTableSlicer AddTableSlicer(ExcelTableColumn TableColumn) /// The slicer drawing internal ExcelPivotTableSlicer AddPivotTableSlicer(ExcelPivotTableField Field) { - if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0) - { - throw new InvalidOperationException("Chart worksheets can't have more than one drawing"); - } if (!string.IsNullOrEmpty(Field.Cache.Formula)) { throw new InvalidOperationException("Can't add a slicer to a calculated field"); @@ -1524,10 +1503,6 @@ internal ExcelPivotTableSlicer AddPivotTableSlicer(ExcelPivotTableField Field) /// The shape object public ExcelShape AddShape(string Name, ExcelShape Source) { - if (Worksheet is ExcelChartsheet && _drawingsList.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"); @@ -1554,10 +1529,6 @@ public ExcelShape AddShape(string Name, ExcelShape Source) /// Drawing names must be unique public ExcelControl AddControl(string Name, eControlType ControlType) { - if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0) - { - throw new InvalidOperationException("Chart worksheets can't have more than one drawing"); - } if (_drawingNames.ContainsKey(Name)) { throw new ArgumentException("Name already exists in the drawings collection"); diff --git a/src/EPPlusTest/Drawing/Chart/ChartShapeTest.cs b/src/EPPlusTest/Drawing/Chart/ChartShapeTest.cs index e1fb90826..bb404751d 100644 --- a/src/EPPlusTest/Drawing/Chart/ChartShapeTest.cs +++ b/src/EPPlusTest/Drawing/Chart/ChartShapeTest.cs @@ -11,6 +11,17 @@ namespace EPPlusTest.Drawing.Chart [TestClass] public class ChartShapeTest : TestBase { + [TestMethod] + public void ShapeInChart() + { + using var p = OpenTemplatePackage("Cheert.xlsx"); + var cheert = p.Workbook.Worksheets["Chart1"]; + var chart = cheert.Drawings[0] as ExcelChartStandard; + chart.Drawings.AddShape("myshpe", eShapeStyle.ActionButtonReturn); + SaveAndCleanup(p); + } + + [TestMethod] public void ShapeInChartTest() {