Export GridView to Excel's key (Downmoon)

xiaoxiao2021-03-18  192

Export cries from GridView to Excel: TOEXCEL (GVSTAFF, TextBox1.text);

public

Static

Void

TOEXCEL (System.Web.ui.Control CTL,

String

Filename)

...

{HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = "application / ms-excel"; HttpContext.Current .Response.AppendHeader ( "Content-Disposition", "attachment; filename =" "" fileName ".xls"); ctl.Page.EnableViewState = false; System.IO.StringWriter tw = new System.IO.StringWriter (); Htmltextwriter hw = new HTMLTextWriter (TW); CTL.RenderControl (HW); httpContext.current.Response.write (Tw.Tostring ()); httpContext.current.Response.end ();}

Must have the following sentence! Otherwise it will not pass!

Public Override Void VerifyrenderingInServerform (Control Control)

...

{// confirms this an HTMLFORM control is rendered for}

转载请注明原文地址:https://www.9cbs.com/read-129871.html

New Post(0)