如何以编程方式将图像设置为随单元格移动和调整大小?

How can I programmatically set images to move and size with cells?

您可以通过右键单击图像,单击 "Size and Properties",然后选择 "Properties" 来更改 Excel 中调整列和行的大小对图像的影响方式。默认情况下,它是 "Move but don't size with cells"。我想使用 EPPlus 以编程方式将图像设置为 "Move and size with cells"。如果那不可能,是否可以将 sheet 上的所有图像都更改为 "Move and size with cells"?

这是插入每张图片的代码:

System.Drawing.Image thumbnail = System.Drawing.Image.FromFile(imagePath);                            
var picture = worksheet.Drawings.AddPicture(data, thumbnail);
picture.SetSize(65, 20);                            
picture.SetPosition(j - 1, 0, 3 + x++, 0);

EditAs设置中将图片设为TwoCell

picture.EditAs = eEditAs.TwoCell;

这将告诉 excel 拉伸它。