Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images in Excel are not being resized properly anymore #1496

Open
countdown opened this issue Feb 22, 2025 · 0 comments
Open

Images in Excel are not being resized properly anymore #1496

countdown opened this issue Feb 22, 2025 · 0 comments

Comments

@countdown
Copy link

countdown commented Feb 22, 2025

NPOI Version

2.7.2

File Type

Checked with XLSX and XLS

Upload the Excel File

testexcel.xlsx

Image

Reproduce Steps

IWorkbook workbook = new SXSSFWorkbook();
ISheet sheet = workbook.CreateSheet("Sheet1");

byte[] imageBytes = File.ReadAllBytes("lock.png");
int pictureIndex = workbook.AddPicture(imageBytes, PictureType.PNG);

IDrawing drawing = sheet.CreateDrawingPatriarch();
ICreationHelper helper = workbook.GetCreationHelper();
IClientAnchor anchor = helper.CreateClientAnchor();

// Set the top-left corner of the image
anchor.Col1 = 1;
anchor.Row1 = 1;
anchor.AnchorType = AnchorType.DontMoveAndResize;

IPicture picture = drawing.CreatePicture(anchor, pictureIndex);
picture.Resize(); // This will resize the picture to its original size

using (FileStream fileStream = new FileStream("D:\\testexcel.xlsx", FileMode.Create, FileAccess.Write))
{
    workbook.Write(fileStream);
}

Issue Description

In the latest version inserting an image and using .Resize() with the intention to resize the image to its original size in an excel workbook (both XSSF and SXSSF) is not working anymore. The image stays very small. I have a attached the sample code with which to reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants