2010-01-09 183 views
1

我需要將一些(可能只是一個或多個)Microsoft圖表導出爲PDF和Excel。它需要發生在點擊按鈕上,並且圖表應直接導出到PDF而不會呈現到網頁上。將MS圖表導出爲PDF和Excel

環境中使用:ASP.NET

請建議的方式來實現這一目標。

歡呼聲

回答

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