Standard plain text for exporting tables to excel

Source: Internet
Author: User

There are many ways to export data to excel. For some complicated formats, I like to splice a <Table> In the background before using response output.

If the data contains Chinese characters or some special characters, many nonstandard writing methods may cause page garbled characters. Here we will bring you the most standard format (I think:

 

Page p = HttpContext.Current.Handler as Page;p.Response.Clear();p.Response.Buffer = true;p.Response.Charset = "UTF-8";p.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, Encoding.UTF8) + ".xls");p.Response.ContentEncoding = Encoding.UTF8;p.Response.ContentType = "application/vnd.ms-excel";p.EnableViewState = false;p.Response.Write("


Note the following two points for the above Code:

1) charset/appendheader/contentencoding must all use utf8

2) if there is only <Table> in text, <HTML>

 

 

 

Now, no garbled characters are involved in how you export an Excel file.

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.