Skip to content

Commit

Permalink
fixed issue #1475
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianEPPlus committed Jun 11, 2024
1 parent deda8f0 commit ff59a2c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/EPPlus/Drawing/ExcelDrawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ public void SetPosition(int Row, int RowOffsetPixels, int Column, int ColumnOffs
SetPixelWidth(_width);
SetPixelHeight(_height);
_doNotAdjust = false;
UpdatePositionAndSizeXml();
}
/// <summary>
/// Set size in Percent.
Expand All @@ -1154,6 +1155,7 @@ public virtual void SetSize(int Percent)
SetPixelWidth(_width);
SetPixelHeight(_height);
_doNotAdjust = false;
UpdatePositionAndSizeXml();
}
/// <summary>
/// Set size in pixels
Expand All @@ -1169,6 +1171,7 @@ public void SetSize(int PixelWidth, int PixelHeight)
SetPixelWidth(PixelWidth);
SetPixelHeight(PixelHeight);
_doNotAdjust = false;
UpdatePositionAndSizeXml();
}
#endregion
/// <summary>
Expand Down
45 changes: 45 additions & 0 deletions src/EPPlusTest/Drawing/CopyDrawingTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OfficeOpenXml;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
using OfficeOpenXml.Table;
using OfficeOpenXml.Drawing.Chart;
using OfficeOpenXml.Drawing.Chart.Style;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace EPPlusTest.Drawing
Expand Down Expand Up @@ -277,5 +282,45 @@ public void CopyDrawingsRange()
ws3.Cells["A1:Z50"].Copy(ws3.Cells["AA1:AZ50"]);
SaveAndCleanup(p);
}


private class Item
{
public string? Name { get; set; }

public int Value { get; set; }
}

[TestMethod]
public void issue1475()
{
using var package = new ExcelPackage();
var ws = package.Workbook.Worksheets.Add("Sheet1");


IEnumerable<Item> _items = new List<Item>() {
new Item { Name = "Bob", Value = 3 },
new Item { Name = "Lisa", Value = 8 },
new Item { Name = "Steve", Value = 5 },
new Item { Name = "Phil", Value = 2 },
};

var range = ws.Cells["A1"].LoadFromCollection(_items, true, TableStyles.Dark1);
var chart = ws.Drawings.AddLineChart("LineChartWithDroplines", eLineChartType.Line);
var serie = chart.Series.Add(range.TakeSingleColumn(1), range.TakeSingleColumn(0));
serie.Header = "Order Value";
chart.SetPosition(0, 0, 6, 0);
chart.SetSize(1200, 400);
chart.Title.Text = "Line Chart With Droplines";
chart.AddDropLines();
chart.DropLine.Border.Width = 2;
//Set style 12
chart.StyleManager.SetChartStyle(ePresetChartStyle.LineChartStyle12);


var cpyWs = package.Workbook.Worksheets.Add("Copy", ws);
cpyWs.View.TabSelected = false;
package.SaveAs("C:\\epplusTest\\Testoutput\\i1475.xlsx");
}
}
}

0 comments on commit ff59a2c

Please sign in to comment.