解决mvc 导出 excel 一行或两行乱码 两行以上正常

来源:互联网 发布:js求一个盒子的宽高 编辑:程序博客网 时间:2024/06/02 02:27

           Response.Clear();
           Response.Buffer = true;
           Response.ContentType = "application/ms-excel;charset=GBK";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.xls", DateTime.Now.ToString("yyyy.MM.dd.hh.mm.ss"))); 

改为

           Response.Buffer = true;

           Response.ContentType = "application/ms-excel;charset=GBK";
            Response.ContentEncoding = System.Text.Encoding.Default;
            Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.xls", DateTime.Now.ToString("yyyy.MM.dd.hh.mm.ss")));
原创粉丝点击