Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Web;
Using System. Web. UI.
Using System. Web. UI. WebControls;
Public partial class _Default: System. Web. UI. Page
{
//& lt; summary>
///Excel data export function
///& lt;/summary>
///& lt; Param name="CTL & gt;" Need to export the data controls & lt;/param>
///& lt; Param name="FileName" & gt; The exported Excel file name & lt;/param>
Private void ToExcel (Control CTL, string FileName)
{
HttpContext. Current. The Response. ContentEncoding=System. Text. The Encoding. GetEncoding (" GB2312 ");
HttpContext. Current. The Response. The Charset="GB2312";
HttpContext. Current. The Response. The ContentType="application/ms - excel";
HttpContext. Current. The Response. AppendHeader (" the Content - the Disposition ", "legislation; Filename="+" "+ filename);
CTL. Page. EnableViewState=false;
System. IO. StringWriter tw=new System. IO. StringWriter ();
HtmlTextWriter hw=new HtmlTextWriter (tw);
CTL. RenderControl (hw);
HttpContext. Current. The Response. The Write (tw) ToString ());
HttpContext. Current. The Response. The End ();
}
Protected void Page_Load (object sender, EventArgs e)
{
}
Protected void Button1_Click (object sender, EventArgs e)
{
Gv. AllowPaging=false;//set the GridView control can't paging
Gv. AllowSorting=false;//set the GridView control can't order
Gv. DataBind ();
ToExcel (gv, "JWTYBH. XLS");
Gv. AllowPaging=true;//restore the GridView control page
Gv. AllowSorting=true;//return the GridView control order
Gv. DataBind ();//data binding function
}
Public override void VerifyRenderingInServerForm Control (Control)
{
//Confirms that the an HtmlForm control is rendered for
}
}
CodePudding user response:
Have resolved theImports System
Imports System. Collections. The Generic
Imports System. Linq
Imports System. Web
Imports System. Web. UI. WebControls
Partial Class _Default
Inherits System. Web. UI. Page
Private Sub ToExcel (ByVal CTL As Control, ByVal FileName As String)
HttpContext. Current. The Response. ContentEncoding=System. Text. Encoding. GetEncoding (" GB2312 ")
HttpContext. Current. The Response. The Charset="GB2312
"HttpContext. Current. The Response. The ContentType="application/ms - excel"
HttpContext. Current. The Response. AppendHeader (" the Content - the Disposition ", "legislation; Filename="& amp; "" & amp; FileName)
CTL. Page. EnableViewState=False
Dim tw As System. IO. StringWriter=New System. IO. StringWriter ()
Dim hw As HtmlTextWriter=New HtmlTextWriter (tw)
CTL. RenderControl (hw)
HttpContext. Current. The Response. The Write (tw) ToString ())
HttpContext. Current. The Response. [End] ()
End Sub
Protected Sub Button1_Click (sender As Object, As EventArgs e) Handles for. Click
Gv. AllowPaging=False
Gv. AllowSorting=False
Gv. DataBind ()
ToExcel (gv, "JWTYBH. XLS")
Gv. AllowPaging=True
Gv. AllowSorting=True
Gv. DataBind ()
End Sub
Public Overrides Sub VerifyRenderingInServerForm (ByVal control As the control)
End Sub
The End of the Class
CodePudding user response:
http://converter.telerik.com/