ASP.NET EXCEL导出的问题,高手帮一下忙.
<%@ Page Language= "C# " AutoEventWireup= "true " CodeFile= "Default.aspx.cs " Inherits= "_Default " %>
<%@ Register Assembly= "WFNetCtrl " Namespace= "WFNetCtrl " TagPrefix= "cc1 " %>
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<asp:Button ID= "Button2 " runat= "server " OnClick= "Button2_Click " Text= "Button " />
<asp:Button ID= "Button1 " runat= "server " OnClick= "Button1_Click " Text= "Button " />
<asp:GridView ID= "GridView1 " runat= "server ">
</asp:GridView>
</form>
</body>
</html>
protected void Button2_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "gb2312 ";
Response.AppendHeader( "content-disposition ", "attachment;filename=filename.xls ");
// 如果设置为 getencoding( "gb2312 ");导出的文件将会出现乱码!!!
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.ContentType = "application/ms-excel ";//设置输出文件类型为excel文件。
System.IO.StringWriter ostringwriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter ohtmltextwriter = new System.Web.UI.HtmlTextWriter(ostringwriter);
this.GridView1.RenderControl(ohtmltextwriter);
< <这一句报错> > 类型“GridView”的控件“GridView1”必须放在具 有 runat=server 的窗体标记内。
Response.Output.Write(ostringwriter.ToString());
Response.Flush();
&n