开发者

Export MS Charts to PDF and Excel

I need to export a few (could be just one or more tha开发者_如何转开发n 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


Here is an example: Microsoft Chart Controls to PDF with iTextSharp and ASP.NET MVC


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜