[英]Why does an image display at greater that its actual size when pasting into Excel, and how can I get it to display at its natural size?
我有这个代码将图像粘贴到 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% 或其他东西才能使其相同?
尝试输入-1
表示 这里提到的width
和height
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.