积极答复者
ASP.NET 通过NOPI 生成EXCEL 的问题

问题
答案
-
你好,
我建议你可以尝试使用Response.ContentEncoding属性对导出的内容进行编码
Response.ContentEncoding = Encoding.UTF8;
这里有些博客你可以参考他们:
- 已建议为答案 Zhi LvModerator 2015年10月20日 7:56
- 已标记为答案 Zhi LvModerator 2015年11月4日 6:21
全部回复
-
奇怪我的代码基本上一样,没有问题啊
protected void Button2_Click(object sender, EventArgs e) { IWorkbook workbook = new HSSFWorkbook(); ISheet sheet = workbook.CreateSheet(("MySheet")); sheet.CreateRow(0).CreateCell(0).SetCellValue("0"); sheet.CreateRow(1).CreateCell(0).SetCellValue("1"); sheet.CreateRow(2).CreateCell(0).SetCellValue("2"); sheet.CreateRow(3).CreateCell(0).SetCellValue("3"); sheet.CreateRow(4).CreateCell(0).SetCellValue("4"); sheet.CreateRow(5).CreateCell(0).SetCellValue("5"); using (MemoryStream ms = new MemoryStream()) { workbook.Write(ms); byte[] content = ms.ToArray(); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", string.Format("attachement; filename=Workbook.xls")); Response.BinaryWrite(content); Response.End(); } }
结果是这样的
我的工程是.net Framework 4.5.1, NPOI版本是2.2.0.0
-
奇怪我的代码基本上一样,没有问题啊
protected void Button2_Click(object sender, EventArgs e) { IWorkbook workbook = new HSSFWorkbook(); ISheet sheet = workbook.CreateSheet(("MySheet")); sheet.CreateRow(0).CreateCell(0).SetCellValue("0"); sheet.CreateRow(1).CreateCell(0).SetCellValue("1"); sheet.CreateRow(2).CreateCell(0).SetCellValue("2"); sheet.CreateRow(3).CreateCell(0).SetCellValue("3"); sheet.CreateRow(4).CreateCell(0).SetCellValue("4"); sheet.CreateRow(5).CreateCell(0).SetCellValue("5"); using (MemoryStream ms = new MemoryStream()) { workbook.Write(ms); byte[] content = ms.ToArray(); Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", string.Format("attachement; filename=Workbook.xls")); Response.BinaryWrite(content); Response.End(); } }
结果是这样的
我的工程是.net Framework 4.5.1, NPOI版本是2.2.0.0
-
-
你好,
我建议你可以尝试使用Response.ContentEncoding属性对导出的内容进行编码
Response.ContentEncoding = Encoding.UTF8;
这里有些博客你可以参考他们:
- 已建议为答案 Zhi LvModerator 2015年10月20日 7:56
- 已标记为答案 Zhi LvModerator 2015年11月4日 6:21