asp.net export Excel Display Chinese garbled solution _ practical Tips

Source: Internet
Author: User

Copy Code code as follows:

protected void Btnexcel_click (object sender, EventArgs e)
{
list<buflow.model.orderhistory> orderlist = dal. GetOrderList2 ("");
string filename = "3g Traffic Network Age upgrade Schedule User table";
string name1 = filename;
String bname = Common.MyRequest.GetBrowserName (). ToLower ();
if (bname. Contains ("Firefox"))
{
}
else if (bname. Contains ("ie"))
{
filename = httputility.urlencode (filename, System.Text.Encoding.UTF8);
}
Else
{
filename = httputility.urlencode (filename, System.Text.Encoding.UTF8);
}

HttpResponse resp = System.Web.HttpContext.Current.Response;
Resp. Charset = "Utf-8";
Resp. Clear ();
Resp. Appendheader ("Content-disposition", "attachment;filename=" + filename + ". xls");
Resp. ContentEncoding = System.Text.Encoding.UTF8;

Resp. ContentType = "Application/ms-excel";
String style = "<meta http-equiv=\" content-type\ "content=\" application/ms-excel; Charset=utf-8\ "/>" + "<style> table{font:9pt Tahoma, Verdana; Color: #000000;  Text-align:center;  Background-color: #8ECBE8; }.table Td{text-align:center;height:21px;background-color: #EFF6FF;  Table th{font:9pt Tahoma, Verdana; color: #000000; font-weight:bold; Background-color: #8ECBEA; height:25px; Text-align:center; padding-left:10px;} </style> ";
Resp. Write (style);
Resp. Write (exporttable (list));
Resp. Write ("<table class= ' table ' ><tr><th>" + "mobile" + "</th><th>" + "channel" + "</th><th > "+" Time "+" </th></tr> ");
Dbvideolist = (list<subshiyongmodel>) session["Dbvideolist"];
foreach (BUFlow.Model.orderhistory Model in orderlist)
{
Resp. Write ("<tr><td>" + Model.phone + "</td>");
Resp. Write ("<td>" + Model.qudao + "</td>");
Resp. Write ("<td>" + model.tm + "</td>");
Resp. Write ("</tr>");
}
Resp. Write ("<table>");

Resp. Flush ();
Resp. End ();
}


Note that the coding problem, in the output, it is best to add the following statement:
Copy Code code as follows:

<meta http-equiv= "Content-type" content= "application/ms-excel; charset=gb2312 "/>

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.