使用 ClosedXML 如何根据行高调整图像大小

Using ClosedXML how to adjust image size according row height

我设置了行高。之后我将图片放在第一个单元格中。如何根据行高调整图像大小?

worksheet.Row(1).Height = 265;
var image = worksheet.AddPicture(imagePath).MoveTo(worksheet.Cell("A1"));

worksheet.Row(1).Height = 265 语句仅更改 的高度。如果你想改变 image 的高度,使用像这样的东西:

var image = worksheet.AddPicture(imagePath).MoveTo(worksheet.Cell("A1")).WithSize(265, 265);

要保留图像的比例,您可以使用缩放方法

        ws.Row(1).Height = 300;
        var pic = ws.AddPicture(imageFile, "Logo").MoveTo(ws.Cell(1, 1));            
        pic.Scale( ws.Row(1).Height / (pic.OriginalHeight * 0.75d));