我已经成功导出了 excel 文件,但问题是导出的 excel 文件没有在 android 中打开,而我看到许多将文件导出到 excel 的应用程序并且在 android 上打开了相同的文件,那为什么不是我的导出文件呢?
//filled dt sucessfully
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dt);
Response.Buffer = true;
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
//response starts
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.CacheControl = "private";
Response.Charset = System.Text.UTF8Encoding.UTF8.WebName;
Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
Response.AppendHeader("Content-Length", MyMemoryStream.Length.ToString());
Response.AppendHeader("Pragma", "cache");
Response.AppendHeader("Expires", "60");
Response.AppendHeader("Content-Disposition",
"attachment; " +
"filename=\"Reports.xlsx\"; " +
"size=" + MyMemoryStream.Length.ToString() + "; " +
"creation-date=" + DateTime.Now.ToString() + "; " +
"modification-date=" + DateTime.Now.ToString() + "; " +
"read-date=" + DateTime.Now.ToString());
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}