asp.NetエクスポートExcel中国語文字化けしの解決方法

10250 ワード

 
  
  protected void btnExcel_Click(object sender, EventArgs e)
    {
        List orderlist = dal.GetOrderList2("");
        string filename = "3g ";
        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 =""+ "";
        resp.Write(style);
        //resp.Write(ExportTable(list));
        resp.Write("

");
        //dbVideoList = (List)Session["dbVideoList"];
        foreach (bUFlow.Model.orderhistory model in orderlist)
        {
            resp.Write("
");
            resp.Write("");
            resp.Write("");
            resp.Write("");
        }
        resp.Write("
" +" "+ "" + " " + "" +" " + "
" + model.phone + "" + model.qudao + "" + model.tm + "
");

        resp.Flush();
        resp.End();
    }

 


  , , :