Export Chart to excel using C#

Jan 25 2014 6:03 AM
Hi Everyone,
 
I have to created the project like to bind the data from the database into chart. Now it works fine. But i need to export that chart to excel. I search this site for how to export, i got this coding from here,
 

string tmpChartName = "ChartImage.jpg";

string imgPath = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName;

chart.SaveImage(imgPath);

string imgPath2 = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName);

Response.Clear();

Response.ContentType = "application/vnd.ms-excel";

Response.AddHeader("Content-Disposition", "attachment; filename=Chart.xls;");

StringWriter stringWrite = new StringWriter();

HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

string headerTable = @"

";

Response.Write(headerTable);

Response.Write(stringWrite.ToString());

Response.End();

           when i was paste this coding it produce the errors in response,request,httprequest,htmltextwriter.. etc.. I dont know where should i change and is there any references will add my end. Please anyone explain me. I developed the chart using windows application c#. Thanks in advance.
 
  

Answers (4)