-
Notifications
You must be signed in to change notification settings - Fork 297
Description
EPPlus usage
Commercial use (I have a commercial license)
Environment
Windows
Epplus version
8.3.0
Spreadsheet application
Excel
Description
In Microsoft Excel, you can create a chart and move the chart to a new chart sheet, and you can add MULTIPLE shapes onto the chart sheet:
However, the current EPPlus explicitly prohibits this. Calling ExcelDrawings.AddShape(String, eShapeStyle) more than once will throw an error:
System.InvalidOperationException : Chart worksheets can't have more than one drawing
Example:
var package = new ExcelPackage();
var chartSheet = package.Workbook.Worksheets.AddChart("Chart", eChartType.XYScatter);
var scatterChart = (ExcelScatterChart)chartSheet.Chart;
// Attempt to add 2 shapes to the chart
var shape1 = scatterChart.Drawings.AddShape("Shape 1", eShapeStyle.Rect);
var shape2 = scatterChart.Drawings.AddShape("Shape 2", eShapeStyle.Rect); // Error: Chart worksheets can't have more than one drawingThe error is thrown explicitly in the method in the source code, in ExcelDrawings.cs:
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");
}
...Adding multiple shapes to a chart sheet should be allowed. This is allowed in Excel, and it is also allowed in the current EPPlus if you are adding the shapes to a normal work sheet instead of a chart sheet. Removing this error throw should solve the issue.
Pull Request: #2184
Thanks!
Metadata
Metadata
Assignees
Labels
Type
Projects
Status