从gridview导出Excel [英] Excel Export from gridview
本文介绍了从gridview导出Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从gridview导出到Excel工作表.
我添加了这样的代码:
I want to export from gridview to excel sheet.
I have added code like that:
try
{
System.Web.UI.WebControls.Repeater gvSource = (System.Web.UI.WebControls.Repeater)Source;
string attachment = "attachment; filename=" + strFileName.Trim().ToUpper() + ".xls";
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "application/ms-excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
// htw.WriteLine("<H1>" + lblHeader.Text.ToString() + ddlAccounts.Text.ToString()+ "<H1>");
gvSource.RenderControl(htw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
catch (Exception Ex)
{
}
在excel中,我们具有设置页眉和页脚的属性.
In excel we have property to set Header and footer. Can we have same facility in C#.net to set header and footer for excel export?
推荐答案
excel超级XML格式,您可以让DataTable Output XML然后将扩展名更改为xls
excel supper XML format ,you let DataTable Output XML then change extention name to xls
这篇关于从gridview导出Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文