Copy codeThe Code is as follows:
Protected void btnExcel_Click (object sender, EventArgs e)
{
List <bUFlow. Model. orderhistory> orderlist = dal. GetOrderList2 ("");
String filename = "3G traffic network age Upgrade Plan 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: #8 ECBEA; height: 25px; text-align: center; padding-left: 10px ;}</style> ";
Resp. Write (style );
// Resp. Write (ExportTable (list ));
Resp. write ("<table class = 'table'> <tr> <th>" + "Mobile Phone" + "</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 the encoding problem. It is best to add the following statement in the output:
Copy codeThe Code is as follows:
<Meta http-equiv = "content-type" content = "application/ms-excel; charset = gb2312"/>