我是利用DataGrid导出的excel,因为是很多个,想直接保存到服务器端,当然如果可以在客户端打包下载更好,请问,怎么实现呢?
DataView dv = new DataView(table1); //赋值给datagrid
DataGrid1.DataSource = dv;
DataGrid1.DataBind(); //保存在files文件夹下
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
string xls_name = tab_cla.Rows[i]["CLA_CODE"].ToString().Trim() + ".xls";
string temp = string.Format("attachment;filename={0}", xls_name);
Response.AppendHeader("Content-disposition", temp);
Response.ContentEncoding = System.Text.Encoding.Default;//设置输出流为默认
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
//this.DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
DataView dv = new DataView(table1); //赋值给datagrid
DataGrid1.DataSource = dv;
DataGrid1.DataBind(); //保存在files文件夹下
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
string xls_name = tab_cla.Rows[i]["CLA_CODE"].ToString().Trim() + ".xls";
string temp = string.Format("attachment;filename={0}", xls_name);
Response.AppendHeader("Content-disposition", temp);
Response.ContentEncoding = System.Text.Encoding.Default;//设置输出流为默认
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
//this.DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货