This project has moved. For the latest updates, please go here.


Changing any row height after inserting picture makes it square


After inserting picture I change some other row's height. The result is that picture is square. If I comment out row's height change, picture is rectangular as expected.

Image position and size does not have any impact on that issue. It does not have to be positioned in the row with changed height.
        static void Main(string[] args)
            var targetPath = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), ".xlsx"));

            using (var package = new ExcelPackage())
                var worksheet = package.Workbook.Worksheets.Add("new");

                var image = new Bitmap(150, 50);
                using(var g = Graphics.FromImage(image)) g.FillRectangle(Brushes.Black, 0, 0, 149, 49);

                var picture = worksheet.Drawings.AddPicture("Picture", image);
                worksheet.Row(1).Height = 5;

                package.SaveAs(new FileInfo(targetPath));


file attachments


atiris wrote Feb 13, 2014 at 3:32 PM

I think we only need modify drawing code
maybe new constructor or new parameter inside AddPicture method
to accept pictures as oneCellAnchor
<xdr:oneCellAnchor editAs="oneCell">
and compute related ext values here:
<xdr:ext cx="3857625" cy="1047750" />

atiris wrote Feb 14, 2014 at 9:27 AM

Check my solution here:
(I don`t know if you can set then for pictures correct position and scale, but this fix dimensions for me)

dmitchern wrote Nov 16, 2015 at 7:52 AM

Helly, guys!

I got this problem as well.

And after some research I figured out where the bug is.

It's in the ExcelRow class on the 149 line of code (ExcelRow.cs file).

There is a mistake, when row's Height got changed it recalcs all pictures heights but uses pictures widths inplace of heights, so it's easy to fix.
Just change the line
var pos = _worksheet.Drawings.GetDrawingWidths();
var pos = _worksheet.Drawings.GetDrawingHeight();
P.S. Hope somebody can change that and commit changes to the repo.

SimStars wrote Nov 16, 2015 at 11:27 AM

Would be nice if someone could get this in a new nuget version of the package.

JanKallman wrote Dec 23, 2015 at 6:22 AM

Fixed in changeset 31e4b2540087

tshaikh wrote Aug 18 at 7:24 PM

Which build is this fix available?

SimStars wrote Aug 21 at 7:09 AM

As JanKallman said: 31e4b2540087 Dec 23, 2015
latest commit/changeset is Jul 12 2017
So I hope that this will move to github before 15 dec. and perhaps with repository hooks for auto update the nuget when someone commits to the master branch or merges.