[英]Gridview to Excel
I have a gridview with AutoGenerateDeleteButton
我有一个使用
AutoGenerateDeleteButton
的gridview
And i export this gridview simple this code.. 我导出这个gridview简单这个代码..
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Avukat.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
Response.Write(stringWrite.ToString());
Response.End();
There is no problem with that. 这没有问题。
But in the excel there is a delete column :)) 但在excel中有一个删除列:))
How can i delete the delete column in excel? 如何删除excel中的删除列?
Your problem is you want 2 x "views" of your grid. 您的问题是您想要2 x“视图”的网格。 With & without the delete column.
有和没有删除列。
One for the browser, and one for Excel. 一个用于浏览器,一个用于Excel。
On your export, drop the delete column. 在导出时,删除删除列。 Something something like:
类似的东西:
GridView1.AutoGenerateDeleteButton = false;
GridView1.DataBind();
GridView1.RenderControl(htmlWrite);
Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
您需要在导出之前从GridView
删除该列。
...Or, you can Export to a real Excel 2007 .xlsx
file the proper way, using the OpenXML
libraries. ...或者,您可以使用
OpenXML
库以正确的方式导出到真正的Excel 2007 .xlsx
文件。
Using this C# library, you just need to include the CreateExcelFile
class in your application, and call one function: 使用此C#库,您只需在应用程序中包含
CreateExcelFile
类,并调用一个函数:
DataSet ds = CreateSampleData();
CreateExcelFile.CreateExcelDocument(ds, "C:\\Sample.xlsx");
Full source code, and a demo application are provided, free of charge. 免费提供完整的源代码和演示应用程序。
http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm
Good luck ! 祝好运 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.