C # Encoding settings when exporting Web page data to Excel

Source: Internet
Author: User

1          Public voidDgtoexcel ()2         {3 response.clearcontent ();4Response.Charset ="GB2312";//content Encoding5Response.ContentType ="Application/ms-excel";6response.contentencoding = System.Text.Encoding.GetEncoding ("GB2312");//content Encoding7Response.AddHeader ("content-disposition","attachment;filename="+ Httputility.urlencode ("Repair Parts Summary"+ System.DateTime.Now.ToShortDateString (), System.Text.Encoding.GetEncoding ("UTF-8")) +". xls");//Export File name encoding8System.IO.StringWriter SW =NewSystem.IO.StringWriter ();9HtmlTextWriter HTW =NewHtmlTextWriter (SW);Ten Gri_viewsumfeebyyg.rendercontrol (HTW); OneResponse.Write (getgridtablehtml (GRI_VIEWSUMFEEBYYG));//write the data source in HTML format A Response.End (); -}
View Code

Generally speaking, Excel exported text encoding as long as two kinds of: GB2312, UTF-8.

If the export is garbled, but try to use another encoding.

In addition, it is worth noting that the compatibility of each browser is not the same, it is possible to export the IE file name is not garbled, but in Firefox above the export file name is garbled.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.