Skip to content

Commit 326552a

Browse files
authored
Removed exception thrown when adding more than one shape to a chart sheet. (#2187)
1 parent a1d6bc3 commit 326552a

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

src/EPPlus/Drawing/ExcelDrawings.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,10 +1218,6 @@ private void AddPicture(string Name, ExcelPicture pic)
12181218
}
12191219
private void ValidatePictureFile(string Name, FileInfo ImageFile)
12201220
{
1221-
if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0)
1222-
{
1223-
throw new InvalidOperationException("Chart worksheets can't have more than one drawing");
1224-
}
12251221
if (ImageFile == null)
12261222
{
12271223
throw (new Exception("AddPicture: ImageFile can't be null"));
@@ -1296,10 +1292,6 @@ public ExcelChart AddChartFromTemplate(Stream crtxStream, string name)
12961292
/// <returns>The new chart</returns>
12971293
public ExcelChart AddChartFromTemplate(Stream crtxStream, string name, ExcelPivotTable pivotTableSource)
12981294
{
1299-
if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0)
1300-
{
1301-
throw new InvalidOperationException("Chart worksheets can't have more than one drawing");
1302-
}
13031295
CrtxTemplateHelper.LoadCrtx(crtxStream, out XmlDocument chartXml, out XmlDocument styleXml, out XmlDocument colorsXml, out ZipPackagePart themePart, "The crtx stream");
13041296
if (chartXml == null)
13051297
{
@@ -1401,10 +1393,6 @@ public ExcelShape AddShape(string Name, eShapeStyle Style)
14011393
}
14021394
internal ExcelShape AddShape(string Name, eShapeStyle Style, object container = null)
14031395
{
1404-
if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0)
1405-
{
1406-
throw new InvalidOperationException("Chart worksheets can't have more than one drawing");
1407-
}
14081396
if (_drawingNames.ContainsKey(Name))
14091397
{
14101398
throw new Exception("Name already exists in the drawings collection");
@@ -1436,11 +1424,6 @@ internal ExcelShape AddShape(string Name, eShapeStyle Style, object container =
14361424
/// <returns>The slicer drawing</returns>
14371425
public ExcelTableSlicer AddTableSlicer(ExcelTableColumn TableColumn)
14381426
{
1439-
if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0)
1440-
{
1441-
throw new InvalidOperationException("Chart worksheets can't have more than one drawing");
1442-
}
1443-
14441427
if (TableColumn.Table.AutoFilter.Columns[TableColumn.Position] == null)
14451428
{
14461429
TableColumn.Table.AutoFilter.Columns.AddValueFilterColumn(TableColumn.Position);
@@ -1464,10 +1447,6 @@ public ExcelTableSlicer AddTableSlicer(ExcelTableColumn TableColumn)
14641447
/// <returns>The slicer drawing</returns>
14651448
internal ExcelPivotTableSlicer AddPivotTableSlicer(ExcelPivotTableField Field)
14661449
{
1467-
if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0)
1468-
{
1469-
throw new InvalidOperationException("Chart worksheets can't have more than one drawing");
1470-
}
14711450
if (!string.IsNullOrEmpty(Field.Cache.Formula))
14721451
{
14731452
throw new InvalidOperationException("Can't add a slicer to a calculated field");
@@ -1524,10 +1503,6 @@ internal ExcelPivotTableSlicer AddPivotTableSlicer(ExcelPivotTableField Field)
15241503
/// <returns>The shape object</returns>
15251504
public ExcelShape AddShape(string Name, ExcelShape Source)
15261505
{
1527-
if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0)
1528-
{
1529-
throw new InvalidOperationException("Chart worksheets can't have more than one drawing");
1530-
}
15311506
if (_drawingNames.ContainsKey(Name))
15321507
{
15331508
throw new Exception("Name already exists in the drawings collection");
@@ -1554,10 +1529,6 @@ public ExcelShape AddShape(string Name, ExcelShape Source)
15541529
/// <exception cref="ArgumentException">Drawing names must be unique</exception>
15551530
public ExcelControl AddControl(string Name, eControlType ControlType)
15561531
{
1557-
if (Worksheet is ExcelChartsheet && _drawingsList.Count > 0)
1558-
{
1559-
throw new InvalidOperationException("Chart worksheets can't have more than one drawing");
1560-
}
15611532
if (_drawingNames.ContainsKey(Name))
15621533
{
15631534
throw new ArgumentException("Name already exists in the drawings collection");

src/EPPlusTest/Drawing/Chart/ChartShapeTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ namespace EPPlusTest.Drawing.Chart
1111
[TestClass]
1212
public class ChartShapeTest : TestBase
1313
{
14+
[TestMethod]
15+
public void ShapeInChart()
16+
{
17+
using var p = OpenTemplatePackage("Cheert.xlsx");
18+
var cheert = p.Workbook.Worksheets["Chart1"];
19+
var chart = cheert.Drawings[0] as ExcelChartStandard;
20+
chart.Drawings.AddShape("myshpe", eShapeStyle.ActionButtonReturn);
21+
SaveAndCleanup(p);
22+
}
23+
24+
1425
[TestMethod]
1526
public void ShapeInChartTest()
1627
{

0 commit comments

Comments
 (0)