/// <Summary> /// Export to excel /// </Summary> /// <Param name = "control"> Widget </Param> /// <Param name = "encoding"> Export format </Param> /// <Param name = "FILENAME"> File Name </Param> Public Static Void Converttoexcel (system. Web. UI. Control, String Encoding, String Filename ){ // Set file name format to prevent Chinese file names from being garbled String Filename =System. web. httputility. urlencode (encoding. utf8.getbytes (filename); system. web. httpcontext. current. response. clear (); system. web. httpcontext. current. response. buffer = True ; System. Web. httpcontext. Current. response. charset = "" + Encoding + "" ; // The following line is very important. The attachment parameter indicates downloading as an attachment. You can change it to online. // Filename=fileflow.xls specifies the name of the output file. Note that the extension is consistent with the specified file type. It can be. Doc. xls. txt. htm. System. Web. httpcontext. Current. response. appendheader ( " Content-Disposition " , " Attachment; filename = " + Filename); system. Web. httpcontext. Current. response. contentencoding = System. Text. encoding. getencoding ( "" + Encoding + "" ); // Response. contenttype specifies the file type which can be application/MS-Excel, application/MS-word, application/MS-txt, application/MS-HTML, or other browsers can directly support documents. System. Web. httpcontext. Current. response. contenttype = " Application/MS-Excel " ; Control. enableviewstate = False ; // Define an input stream System. Io. stringwriter ostringwriter = New System. Io. stringwriter (); system. Web. UI. htmltextwriter ohtmltextwriter = New System. Web. UI. htmltextwriter (ostringwriter); control. rendercontrol (ohtmltextwriter ); // This indicates that the current page is output. You can also bind the DataGrid or other controls that support the obj. rendercontrol () attribute. System. Web. httpcontext. Current. response. Write (ostringwriter. tostring (); system. Web. httpcontext. Current. response. End ();}
This method is used as the rendering output!
/// <Summary> /// this method must be overwritten, otherwise, an error occurs. // </Summary> // <Param name = "control"> </param> Public override void verifyrenderinginserverform (Control ){}