20

MVC NPOI 导出excel 2007 文件损坏

MVC下用NPOI导出excel2007,无法打开文件,提示文件已经损坏。导出2003就没有问题。

        public FileResult Export_()
        {
            XSSFWorkbook workbook = new XSSFWorkbook();
            //创建一个Excel的Sheet
            ISheet sheet = workbook.CreateSheet();
            for (int i = 0; i <= 15; i++)
            {
                IRow row = sheet.CreateRow(i);
                for (int j = 0; j < 15; j++)
                {
                    row.CreateCell(j).SetCellValue(i + "行" + j + "列");
                }
            }

            NpoiMemoryStream ms = new NpoiMemoryStream();
            ms.AllowClose = false;
            workbook.Write(ms);
            ms.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            //var memoryStream = Session["table"] as NpoiMemoryStream;

            workbook.Write(ms);
            ms.Close();

            return File(ms, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "ActualThroughPut.xlsx");
        }

这个怎么解决啊,急急急!!!

查看全部
aa2012123456
小颜学开发
2019/04/08 16:42
  • asp.net
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复