将MS图表导出为PDF和Excel

将MS图表导出为PDF和Excel

问题描述:

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

环境中使用:ASP.NET

请建议的方式来实现这一目标。

欢呼声

下面是用于导出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();