打开 Java POI 创建的 Excel 工作表时出现错误消息

问题描述 投票:0回答:2

使用 Java POI 生成 Excel 工作表并打开新创建的 Excel 文件后,我会收到一个消息框,显示

Excel found unreadable content in "abc.xlxs" .Do you want to recover the contents of this workbook?If you trust the source of this workbook, click 'yes'.

当我单击“是”时,我收到类似这样的消息

Excel was able to open the file by repairing or removing the unreadable content

之后我可以查看工作表中的内容。如何在打开它时删除所有这些类型的消息?

excel apache-poi
2个回答
0
投票

您应该检查您是否使用了正确的API:

  • 对于 .xls 文件,您必须使用 HSSF。
  • 对于 .xlsx 文件,您必须使用 XSSF 或更高版本的 api。

检查你的excel文件是否正确写入。 为了获得正确的答案,请提供一些代码。


0
投票

面临类似的问题,但就我而言,Excel 文件本身无法打开

工作簿wb = new XSSFWorkbook(); OutputStream fileOut = new FileOutputStream(CucumberRunner.testFilePath+"\AutomationTestResult.xlsx");
System.out.println(CucumberRunner.testFilePath+"\AutomationTestResult.xlsx Excel 文件已成功创建。");
wb.write(fileOut); XSSFWorkbook 工作簿 = new XSSFWorkbook();
XSSFSheet Sheet = workbook.createSheet("一月"); XSSFRow rowhead =sheet.createRow((短)0); rowhead.createCell(0).setCellValue("S.No.");
rowhead.createCell(1).setCellValue("客户名称");
rowhead.createCell(2).setCellValue("账号");
rowhead.createCell(3).setCellValue("电子邮件");
rowhead.createCell(4).setCellValue("余额");

error ss - 1

error ss - 2

© www.soinside.com 2019 - 2024. All rights reserved.