代码之家  ›  专栏  ›  技术社区  ›  Arnkrishn

将MS图表导出为PDF和Excel

  •  1
  • Arnkrishn  · 技术社区  · 16 年前

    我需要将一些(可能只是一个或多个)Microsoft图表导出为PDF和Excel。只需点击一个按钮,图表就可以直接导出为PDF格式,而无需呈现在网页上。

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

    干杯

    2 回复  |  直到 16 年前
        2
  •  1
  •   Sugandika    14 年前

        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();
    
    推荐文章