gpt4 book ai didi

c# - EPPlus Excel AddPicture 错误 'Column number out of bounds'

转载 作者:行者123 更新时间:2023-12-04 20:00:00 32 4
gpt4 key购买 nike

我有以下代码:

带有“excelImage”初始化的行会抛出异常:列号越界。
问题的解决方案是什么?

var range2 = worksheet.Cells ["A" + limiter.ToString ()];
range2.Value = tokenGood.id; //Take from JSON-array
worksheet.Row (limiter).Height = 70; //'limiter' is like row iterator
worksheet.Column (1).Width = 10;

Bitmap img = new Bitmap(Image.FromFile (PIC_FILENAME));
OfficeOpenXml.Drawing.ExcelPicture excelImage = worksheet.Drawings.AddPicture ("random_string", img); //Error Line
excelImage.From.Column = 3;
excelImage.From.Row = limiter;
excelImage.SetSize (60, 60);

最佳答案

该错误的解决方法(EPPlus 4.5.3 不检查图像分辨率是否存在于:ExcelDrawing.cs,
内部无效 SetPixelWidth(int 像素,浮点 dpi),第 400 行)。

如果没有设置图像分辨率,只需手动设置即可。 AddPicture 可以正常工作:

if (img.HorizontalResolution == 0 || img.VerticalResolution == 0)
img.SetResolution(96, 96);
var excelImage = worksheet.Drawings.AddPicture("img", img);

关于c# - EPPlus Excel AddPicture 错误 'Column number out of bounds',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35042419/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com