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