作者whileloop (回圈)
看板C_Sharp
标题[问题] 汇出Excel当作资料来源
时间Mon Mar 1 23:24:55 2010
写了下列方式将GridView汇出成Excel档..
汇出的Excel可以正常的用Excel 2003开启
但是若要以此档当作是另一个网页的Source DB时,却会有问题(格式问题)
所以我只好暂时将这个汇出的Excel档另存新档,再以此档当作Source DB
请问该怎麽汇出,Excel格式才是正确的?
protected void Button_ExportExcel_Click(object sender, EventArgs e)
{
Button BTN = sender as Button;
GridView myGridView = BTN.FindControl("GridView1") as GridView;
Response.Clear();
Response.AddHeader("content-disposition","attachment;filename=Export.xls");
Response.Charset = "BIG5";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new HtmlTextWriter(sw);
myGridView.AllowSorting = false;
myGridView.AllowPaging = false;
HtmlForm hf = new HtmlForm();
Controls.Add(hf);
hf.Controls.Add(myGridView);
hf.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 125.225.163.206
1F:→ kinwind:要不要考虑用NPOI输出excel? 03/02 00:30
3F:→ whileloop:感谢! 03/02 23:56