我有2個gridview,它像產品類別和產品目錄一樣工作。 每個類別有幾個產品。將2 gridview導入excel
現在,用戶已經選擇了類別,查看產品目錄後,我想這兩種導出爲Excel
舉例: 選擇產品類別:「水果」 目錄是:「蘋果,香蕉,橙色「
我想存儲選定產品分類以及目錄。
現在,我只能夠出口產品目錄的列表。(簡單的出口1周的GridView中脫穎而出)
我希望我說清楚了。
IM在asp.net C#運行
點擊按鈕均流代碼
string filename = String.Format("Survey Results_{0}_{1}.xls",
DateTime.Today.Month.ToString(), DateTime.Today.Year.ToString());
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
Response.Charset = "";
// SetCacheability doesn't seem to make a difference (see update)
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
// Replace all gridview controls with literals
ClearControls(GridView2);
// Throws exception: Control 'ComputerGrid' of type 'GridView'
// must be placed inside a form tag with runat=server.
// ComputerGrid.RenderControl(htmlWrite);
// Alternate to ComputerGrid.RenderControl above
System.Web.UI.HtmlControls.HtmlForm form
= new System.Web.UI.HtmlControls.HtmlForm();
Controls.Add(form);
form.Controls.Add(GridView2);
form.RenderControl(htmlWriter);
Response.Write(stringWriter.ToString());
Response.End();
自己解決。我想出了一個解決方案,將excel文件名稱作爲選定的「產品類別」。 – 2011-12-20 06:23:47