Question

I need to export a few (could be just one or more than one) Microsoft Charts to a PDF and Excel. It needs to happen on a button click and the charts should be directly exported to a PDF without getting rendered onto a web page.

Environment used: ASP.NET

Please suggest the approach to achieve this.

cheers

Was it helpful?

OTHER TIPS

Here is a sample code for exporting MS chart control to Excel. Hope this helps.

    string tmpChartName = "test2.jpg";
    string imgPath = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName;

    Chart1.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=test.xls;");
    StringWriter stringWrite = new StringWriter();
    HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
    string headerTable = @"<Table><tr><td><img src='" + imgPath2 + @"' \></td></tr></Table>";
    Response.Write(headerTable);
    Response.Write(stringWrite.ToString());
    Response.End();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top