Page.Response.ClearHeaders();
Page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Page.Response.ContentType = "application/msexcel";
Page.Response.AddHeader("Content-Disposition", "attachment; filename=abc.xlsx");
Page.Response.Write("aaaaaaaaaaa");
Page.Response.End();这段代码导出的Excel文件总是无法运行,谁知道是怎么回事。
Page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Page.Response.ContentType = "application/msexcel";
Page.Response.AddHeader("Content-Disposition", "attachment; filename=abc.xlsx");
Page.Response.Write("aaaaaaaaaaa");
Page.Response.End();这段代码导出的Excel文件总是无法运行,谁知道是怎么回事。
string filePath = Server.MapPath("");//路径
FileInfo fileInfo = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(fileInfo.FullName);
Response.Flush();
Response.End();