添加图像到Excel中使用EPPlus [英] Adding images into Excel using EPPlus
问题描述
我试图多次添加相同的图像为使用EPPlus Excel文件。我使用下面的code这样做的:
I am trying to add the same image multiple times into an excel file using EPPlus. I am using the following code to do so:
Image logo = Image.FromFile(path);
ExcelPackage package = new ExcelPackage(info);
var ws = package.Workbook.Worksheets.Add("Test Page");
for(int a = 0; a < 5; a++)
{
ws.Row(a*5).Height = 39.00D;
var picture = ws.Drawings.AddPicture(a.ToString(), logo);
picture.SetPosition(a*5, 0, 2, 0);
}
一切完美,所有的图像都正确添加,但他们向下延伸。下面是图片之一应该是什么样子:
Everything works perfectly and all the images are correctly added but they are stretched downwards. Here is what one of the pictures should look like:
但它看起来像在Excel:
But it looks like this in excel:
我要调整每个图片的开始的每一行,但我不认为这会影响它。会有添加图片/做我想要做或我必须手动将影像复制粘贴的方法吗? (我用的图片为例)
I have to resize each row of the start of each picture but I dont think that would be affecting it. Would there be a way to add the pictures/do what I am trying to do or would I have to copy-paste the images in manually? (I am using the picture as an example)
感谢。
推荐答案
我不知道,如果这是你的问题的最佳解决方案但肯定一个解决办法。
I'm not sure if this is the best solution but definetly a workaround for your problem.
下面是我所做的:
ExcelPackage package = new ExcelPackage();
var ws = package.Workbook.Worksheets.Add("Test Page");
for (int a = 0; a < 5; a++)
{
ws.Row(a * 5).Height = 39.00D;
}
for (int a = 0; a < 5; a++)
{
var picture = ws.Drawings.AddPicture(a.ToString(), logo);
picture.SetPosition(a * 5, 0, 2, 0);
}
下面是它的外观。
由于某些原因,当我们有行高度集中,其干扰与画面高度。
For some reason when we have the row height set, its interfering with the picture height.
这篇关于添加图像到Excel中使用EPPlus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!