将图片插入spreadsheetGear excel

时间:2017-07-21 13:57:48

标签: c# excel image spreadsheetgear

我使用下面的代码在我的Excel工作表中插入徽标,但是我得到的是没有图像的excel

double width;
double height;
System.Drawing.Image image = System.Drawing.Image.FromFile(logo);

using (image)
{
    width = image.Width * 72.0 / image.HorizontalResolution;
    height = image.Height * 72.0 / image.VerticalResolution;
}

SpreadsheetGear.IWorksheetWindowInfo windowInfo = sheet.WindowInfo;
double left = windowInfo.ColumnToPoints(1.5);
double top = windowInfo.RowToPoints(1.5);
sheet.Shapes.AddPicture(logo, left, top, width, height);

然后我将工作簿保存为流并返回文件

workbook.SaveToStream(memStream, SpreadsheetGear.FileFormat.OpenXMLWorkbook);
var mSream = new MemoryStream(memStream.GetBuffer(), 0, (int)memStream.Length);

var FileDownloadName = string.Format("Report");

return File(mSream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", FileDownloadName);

0 个答案:

没有答案