我已将此代码粘贴到Excel中:
. . .
string unitImageLoc = GetUnitImageLoc();
if (unitImageLoc != "image not found")
{
Image img = Image.FromFile(unitImageLoc);
int imgWidth = img.Width;
int imgHeight = img.Height;
_xlSheet.Shapes.AddPicture(unitImageLoc,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoCTrue, 4, 4, imgWidth, imgHeight);
}
private string GetUnitImageLoc()
{
string unitUpper = _unit.ToUpper();
string candidateFile = string.Format("C:\\RoboReporter\\{0}.png",
unitUpper);
if (File.Exists(candidateFile))
{
return candidateFile;
}
return "image not found";
}
它可以工作,但打印的图像大于其实际尺寸,如此处所示(顶部的Excel,如底部的图像查看器中所示):
这不是特定图片的问题:它发生在任何:
所以我需要将宽度和高度乘以70%或者其他东西以使其相同吗?
答案 0 :(得分:1)
尝试按照-1
和width
height
输入user
。