I have generated a chart in my web application (.Net 4.0) using MS Chart Controls. My requirement is to export the particular chart into an Excel file as an image. I have written the below mentioned code attempting to write the chart image to the excel file as a byte array. But it resulted some unknown characters in my excel file. (The byte array might have been written directly to the file).
byte[] bytes2;
using (var chartimage = new MemoryStream())
{
Chart1.SaveImage(chartimage, ChartImageFormat.Png);
bytes2 = chartimage.GetBuffer();
}
Response.Clear();
Response.ContentType = "application/ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=StudentResults.xls");
Response.BinaryWrite(bytes2);
Response.End();
Can any of you please help me to write this chart to an excel file in a correct way? (either without using a byte array would also fine) Thanks