Wednesday, 7 August 2013

How to Insert image into excel sheet without using Microsoft.Office.Interop.Excel

How to Insert image into excel sheet without using
Microsoft.Office.Interop.Excel

I have a chart in my webpage and I have saved this chart to a .png image
now I want to read the bytes of this .png and inset the image into excel .
I have tried this piece of code
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/excel";
HttpContext.Response.AddHeader("Content-Disposition",
"attachment;filename=Reports.xls");
using (MemoryStream memoryStream = new MemoryStream())
{
_chart.SaveImage(memoryStream, ChartImageFormat.Png);
Response.BinaryWrite(memoryStream.GetBuffer()); //
Writing byte[] array
Response.Flush();
Response.End();
}
But it seems Response.BinaryWrite is not working ...and I dont want to do
it through Workbooks in Microsoft.Office.Interop.Excel Any working
solution??? Thanks in advance.

No comments:

Post a Comment