2

我需要将一些(可能只是一个或多个)Microsoft Charts 导出到 PDF 和 Excel。它需要在单击按钮时发生,并且图表应直接导出为 PDF 而不会呈现到网页上。

使用环境:ASP.NET

请提出实现这一目标的方法。

干杯

4

2 回答 2

5

这是一个示例:Microsoft Chart Controls to PDF with iTextSharp and ASP.NET MVC

于 2010-01-09T00:37:23.213 回答
1

这是将 MS 图表控件导出到 Excel 的示例代码。希望这可以帮助。

    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();
于 2012-05-17T04:52:37.283 回答