【发布时间】:2009-11-13 21:00:01
【问题描述】:
我正在尝试像这样使用 c# 创建一个 xls 文件
protected void ExportToExcel(DataSet dset, int TableIndex, HttpResponse Respone, string Felename)
{
Respone.Clear();
Respone.Charset = "";
Respone.ContentType = "application/vnd.ms-excel";
Respone.AddHeader("content-disposition", "attachment; filename=" + Felename + ".xls");
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
GridView gv = new GridView();
gv.DataSource = dset.Tables[TableIndex];
gv.DataBind();
gv.RenderControl(hw);
Respone.Write(sw.ToString());
Respone.End();
}
它对我来说很好用。但是在成功完成后打开创建的 xls 文件。但我想将文件保存在我的文件夹中,而无需打开并询问我的许可。
如何自动保存..
提前致谢
【问题讨论】:
-
这个 SO 线程和answer link here 是一个很好的方法。