2010-02-22 34 views

回答

0

我發現和excel一起工作真是令人頭疼,但如果你願意,可以做任何事情。您需要利用哪些功能,因爲提供csv文件要容易得多!

您是否擁有SSRS,您可以將查詢作爲SSRS報告提供,並且可以自動作爲excel下載使用!

0

如果您在MS SQL Server上提供免費的報告服務,並且可以輕鬆地爲您完成此操作,則還可以導出爲PDF和Word。

如果沒有,或者如果它只是一個一次性try here

0

你能證明你的結果在DataGrid中。之後,您可以將此網格導出爲Excel文件。

是這樣的: 我按會話傳遞網格。

Control grdList; 
GridView grdList1 = Session["GridView"] as GridView; 
if (grdList1 == null) 
{ 
    grdList = (DataGrid)Session["GridView"]; 
} 
else 
{ 
    grdList = (GridView)Session["GridView"]; 
} 

Response.Clear(); 
Response.AddHeader("content-disposition", "attachment;filename=ExportList.xls"); 
Response.Charset = ""; 
// If you want the option to open the Excel file without saving than 
// comment out the line below 
// Response.Cache.SetCacheability(HttpCacheability.NoCache); 
Response.ContentType = "application/vnd.xls"; 
Response.ContentEncoding = System.Text.Encoding.UTF8;// GetEncoding(1256);// UTF8; 
System.IO.StringWriter stringWrite = new System.IO.StringWriter(); 
System.Web.UI.HtmlTextWriter htmlWrite = 
new HtmlTextWriter(stringWrite); 
grdList.RenderControl(htmlWrite); 
Response.Write(stringWrite.ToString()); 
Response.End();