我正在尝试使用浏览器中的内置下载来下载 Excel 文件。基本上,在我的控制器中创建 Excel 文件后,下载工作正常,但是当我尝试在 Excel 中打开此文件时,我被告知该文件已损坏:
Excel 无法打开文件“Report.xlsx”,因为文件格式或文件扩展名无效。验证文件未损坏并且文件扩展名与文件格式匹配。
当强制在 Excel 中打开文件时,工作表只是空的。我不知道这是为什么。
Code
我没有展示如何创建 Excel 文件,因为这是无关紧要的(在使用内存流之前它工作得很好).
var stream = wBook.WriteXLSX(); // Return a MemoryStream (Using DTG.Spreadsheet)
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Report.xlsx");
您应该将当前流位置设置为 0 才能成功导出文件。
var stream = wBook.WriteXLSX(); // Return a MemoryStream (Using DTG.Spreadsheet)
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Report.xlsx");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)