为什么在粘贴到Excel时图像的显示大于其实际大小,如何使其以自然大小显示?

时间:2016-03-18 19:03:24

标签: c# image excel-interop image-scaling image-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,如底部的图像查看器中所示):

enter image description here

这不是特定图片的问题:它发生在任何:

enter image description here

所以我需要将宽度和高度乘以70%或者其他东西以使其相同吗?

1 个答案:

答案 0 :(得分:1)

尝试按照-1width height输入user