将gridview数据导出为excel 2007格式 [英] Export gridview data to excel 2007 format
本文介绍了将gridview数据导出为excel 2007格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有以下代码将数据导出为excel 2003格式:
protected void lnkbtnExport_Click(object sender,EventArgs e)
{
ExcelHead.Visible = true;
string fileName =attachment; filename = UserProdReport_+ DateTime.Now.ToString(dd-MM-yyyy-hh-mm-ss)+。xls;
Response.Clear();
Response.AddHeader(content-disposition,fileName);
Response.Charset =;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType =application / excel;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
ExcelHead.RenderControl(htmlWrite);
gvUserProd.RenderControl(htmlWrite);
Response.Write(stringWrite);
Response.End();
ExcelHead.Visible = false;
}
现在我想将它导出为excel 2007格式..请有人给我一个主意。
问候,
解决方案
试试这个 -
Response.ContentType =application / vnd .openxmlformats-officedocument.spreadsheetml.sheet;
HTH
Rajeev
如果有帮助,请投票并将答案标记为已接受
< blockquote>对于 .xlsx 讨论:
http://forums.asp.net/t/1221467.aspx/1?Export+GridView+to+Excel+xlsx+Excel+2007+Format+ [ ^ ]
对于 .xls ,你得到的就足够了此处
你好
看看这个
将GridView导出到Excel [ ^ ]
尝试这种方式&在这里看到很好的讨论
http://www.eggheadcafe.com/tutorials/aspnet/48e4b7c2-7735-4122-83f3-3bc58854b589/client-side-script-to-exp.aspx [ ^ 一>
Hi Everyone,
I have the below code to export the data into excel 2003 format:
protected void lnkbtnExport_Click(object sender, EventArgs e) { ExcelHead.Visible = true; string fileName = "attachment;filename= UserProdReport_" + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ".xls"; Response.Clear(); Response.AddHeader("content-disposition", fileName); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/excel"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); ExcelHead.RenderControl(htmlWrite); gvUserProd.RenderControl(htmlWrite); Response.Write(stringWrite); Response.End(); ExcelHead.Visible = false; }
Now I want to export the same into excel 2007 format.. Please anyone give me an idea.
Regards,
解决方案
Try this -
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HTH
Rajeev
Please vote and mark the answer as accepted if this helps
For .xlsx discussions:
http://forums.asp.net/t/1221467.aspx/1?Export+GridView+to+Excel+xlsx+Excel+2007+Format+[^]
For .xls you get more than enough here
Hi
Have a look on this
Export GridView to Excel[^]
Try in this way & See good discussion here
http://www.eggheadcafe.com/tutorials/aspnet/48e4b7c2-7735-4122-83f3-3bc58854b589/client-side-script-to-exp.aspx[^]
这篇关于将gridview数据导出为excel 2007格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文