Когда я пытаюсь сгенерировать файл Excel с помощью EPPlus, Excel выдает следующее сообщение об ошибке:
Excel не может открыть файл 'myfilename.xlsx', поскольку формат файла или расширение файла недействительны. Убедитесь, что файл не поврежден и что расширение файла соответствует формату файла.
Вот мой код:
public ActionResult Index()
{
using (ExcelPackage package = new ExcelPackage())
{
// I populate the worksheet here. I'm 90% sure this is fine
// because the stream file size changes based on what I pass to it.
var stream = new MemoryStream();
package.SaveAs(stream);
string fileName = "myfilename.xlsx";
string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
var cd = new System.Net.Mime.ContentDisposition
{
Inline = false,
FileName = fileName
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(stream, contentType, fileName);
}
}
Есть идеи, что я делаю неправильно?