4

我想在将图像插入到 Excel 工作表后调整图像大小。我正在插入这样的图片:

Excel.Pictures p = myWorkSheet.Pictures(System.Type.Missing) as Excel.Pictures;
Excel.Picture pic = null;

pic = p.Insert(path + pic_name + ".png", System.Type.Missing);

pic.Left = Convert.ToDouble(picPosition.Left);
pic.Top = picPosition.Top;

我曾尝试在插入之前调整图片大小,但它会降低质量。

4

1 回答 1

1

解决了!!!我刚刚在上面的代码中添加了接下来的三行:

pic.ShapeRange.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoCTrue;
                        pic.ShapeRange.Width = 170;
                        pic.ShapeRange.Height = 170;

所以,现在它看起来像这样:

Excel.Pictures p = myWorkSheet.Pictures(System.Type.Missing) as Excel.Pictures;
Excel.Picture pic = null;

pic = p.Insert(path + pic_name + ".png", System.Type.Missing);

pic.ShapeRange.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoCTrue;
pic.ShapeRange.Width = 170;
pic.ShapeRange.Height = 170;

pic.Left = Convert.ToDouble(picPosition.Left);
pic.Top = picPosition.Top;

而且效果很好。

于 2012-10-12T14:31:05.157 回答