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.
Rupali ShindePosted Nov 17, 2015, 11:32 PM
If it works out, Please Accept this as AnswerRahul PrasadPosted Jul 25, 2014, 4:11 AM
http://www.dotnetbull.com/2011/09/exporting-pie-chart-into-excel-file.html
Darren KangPosted Jul 24, 2014, 4:25 AM
Hi,
First this code snippet is for a web application, not windows application.
Second, I believe I understood your requirement, so you would like to generate a new excel file, fill it with a data from your database and create a chart based on that data.
If I'm correct then try the following, it is a C# snippet for creating a Chart element in a new Excel file. The code uses this .NET library that operates with excel files.
DataTable table = new DataTable();
// Fill DataTable with database's data.
// ...
// Create new excel file.
ExcelFile file = new ExcelFile();
// Create new worksheet.
ExcelWorksheet sheet = file.Worksheets.Add("Sheet 1");
// Insert DataTable to worksheet.
sheet.InsertDataTable(table, new InsertDataTableOptions("A1"));
// Create chart and select data for it.
ExcelChart chart = sheet.Charts.Add(ChartType.Line, "D2", "M25");
chart.SelectData(
sheet.Cells.GetSubrange("A1",
CellRange.RowColumnToPosition(table.Rows.Count - 1, table.Columns.Count - 1)));
// Save file.
file.Save("Chart.xlsx", SaveOptions.XlsxDefault);
Vithal WadjePosted Jan 25, 2014, 1:27 PM