简体   繁体   English

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

[英]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?

I've got this code to paste an image into Excel:我有这个代码将图像粘贴到 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";
}

It works, but prints the image larger than its actual size, as seen here (Excel on top, as appears in image viewer on the bottom):它可以工作,但打印的图像大于其实际大小,如下所示(顶部为 Excel,底部的图像查看器中显示):

在此处输入图片说明

It is not an issue with a specific image: it happens with any:这不是特定图像的问题:它发生在任何:

在此处输入图片说明

So do I need to multiply the width and height by 70% or something to get it to be the same?那么我是否需要将宽度和高度乘以 70% 或其他东西才能使其相同?

尝试输入-1表示 这里提到的widthheight

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在XAML中获取图像以实际尺寸显示? - How can I get images in XAML to display as their actual size? 如何显示窗口大小为原始大小的一半 - How to display a window half of its original size 如何在ListView中显示实际图像而不是它的位置? - How to display an actual image in ListView rather than its location? 当 window 大小发生变化时,如何在装饰器上绘制一个矩形以与它绑定的 Image 元素一起缩放? - How do I get a Rectangle drawn on an adorner to scale with the Image element its bound to when the window size is changed? 当javascript事件的大小通过css设置时,如何使图像放大? - How can I make an image enlarge on a javascript event when its size is set through css? 上传图片后如何显示图片预览 - How to display the image preview when its uploaded 如何在固定大小的Crystal报表中显示图像? - How can I display an image in crystal report with fixed size ? 为什么当我用鼠标拖动pictureBox中的图像时,它将图像恢复为原始大小? - Why when i drag with the mouse the image in the pictureBox it return the image to its original size? 如何获得与窗口大小成比例显示的图像? - How can I get images to display in proportion to the size of the window? winForms中点击size属性设置为CenterImage的pictureBox如何获取图片的实际坐标? - How can I get the actual coordinates of the image when I click on the pictureBox whose size property is set to CenterImage in winForms?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM