C# 的NPOI导出的Excel乱码,版本是NPOI 2.2.0.0怎么办
我是直接给单元格一个字符串T_Customer[]customer=T_CustomerBLL.GetAll();HSSFWorkbookworkbook=newHSSF...
我是直接给单元格一个字符串
T_Customer[] customer = T_CustomerBLL.GetAll();
HSSFWorkbook workbook = new HSSFWorkbook();
ISheet sheet = workbook.CreateSheet("客户信息(" + DateTime.Now.ToString("yyyy-MM-dd") + ")");
IRow headerRow = sheet.CreateRow(0);
/////直接填字符串
headerRow.CreateCell(0, CellType.String).SetCellValue("姓名"); 展开
T_Customer[] customer = T_CustomerBLL.GetAll();
HSSFWorkbook workbook = new HSSFWorkbook();
ISheet sheet = workbook.CreateSheet("客户信息(" + DateTime.Now.ToString("yyyy-MM-dd") + ")");
IRow headerRow = sheet.CreateRow(0);
/////直接填字符串
headerRow.CreateCell(0, CellType.String).SetCellValue("姓名"); 展开
1个回答
展开全部
Your problem is the mis-match of these two lines
XSSFWorkbook workbook = new XSSFWorkbook();
and
response.setContentType("application/vnd.ms-excel");
If you really want to generate a .xls older-style Excel workbook, you need to change the first line to be HSSFWorkbook rather than XSSFWorkbook
If you do mean to generate a .xlsx Excel workbook, then the content type on the second line needs to be the correct .xlsx one, which would be:
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
XSSFWorkbook workbook = new XSSFWorkbook();
and
response.setContentType("application/vnd.ms-excel");
If you really want to generate a .xls older-style Excel workbook, you need to change the first line to be HSSFWorkbook rather than XSSFWorkbook
If you do mean to generate a .xlsx Excel workbook, then the content type on the second line needs to be the correct .xlsx one, which would be:
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
追问
不太懂
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询