I have a MVC application that uses NPOI version:2.1.3.0 to read and write in excel file and user can download that excel file in their local machine. File format: xlsx.
public ActionResult NPOI()
{
FileStream fs = new FileStream(Server.MapPath(@"\Content\SampleExcel.xlsx"), FileMode.Open, FileAccess.Read);
XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
ISheet sheet = (ISheet)templateWorkbook.GetSheet("Sheet1");
IRow dataRow = (IRow)sheet.GetRow(1);
dataRow.GetCell(0).SetCellValue(77);
sheet.ForceFormulaRecalculation = true;
MemoryStream ms = new MemoryStream();
templateWorkbook.Write(ms);
return File(ms.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "SampleExcel.xlsx");
}
Writing in excel file is working fine. But when browser is IE and excel 2013 in user machine.
If after downloads completes user uses IE open(preview file) option is selected:
Then in excel 2013 this error is observed:
Followed by:
Although the template file(SampleExcel.xlsx) which is there on server side is open and saved with excel 2013. Then also I don't know why it is showing file is corrupt. And there is enough memory on user's machine, it never touches it's peak value in task manager. Any help would be highly appreciated.
I figured it out, actually the problem is not with the memory, but with the user permission on that particular machine. If Admin guys try to do same above mentioned steps with no customization in access then no problem is faced by him.
Anyhow thanks everyone for your time:)