nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Apache License 2.0
5.65k stars 1.42k forks source link

excel file damaged after adding images and saving #1352

Open rick-yang1987 opened 3 months ago

rick-yang1987 commented 3 months ago

NPOI Version

2.6.2

File Type

Upload the Excel File

项目资金预算(原文件).xlsx

Reproduce Steps

1、open file 2、add image 3、save

Issue Description

tonyqus commented 1 month ago

Can you share the code of how you add the image?

rick-yang1987 commented 1 day ago

        static Boolean InsertImage(XSSFWorkbook workbook, ISheet sheet, byte[] imageData, int row, int column, int endRows, int endCols)         {             try             {                 XSSFCellStyle style = (XSSFCellStyle)workbook.CreateCellStyle();                 style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;                 style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;                 XSSFDrawing patriarch = (XSSFDrawing)sheet.CreateDrawingPatriarch();                 XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, column, row, endCols + 1, endRows + 1);                 anchor.AnchorType = AnchorType.MoveAndResize;

                int pictureIndex = workbook.AddPicture(imageData, PictureType.BMP);                 XSSFPicture picture = (XSSFPicture)patriarch.CreatePicture(anchor, pictureIndex);                 picture.LineStyle = LineStyle.None;             }             catch (System.Exception ex)             {                 return false;             }

            return true;         }

461636174 @.***

 

------------------ 原始邮件 ------------------ 发件人: "nissl-lab/npoi" @.>; 发送时间: 2024年7月2日(星期二) 凌晨4:55 @.>; @.**@.>; 主题: Re: [nissl-lab/npoi] excel file damaged after adding images and saving (Issue #1352)

Can you share the code of how you add the image?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>