Excel 在 workspace.xlsx 中发现不可读的内容(POI - java)

Excel found unreadable content in workspace.xlsx (POI - java)

我正在尝试从 java 代码创建工作簿。 我正在为此使用 POI 库,在执行程序后, 工作簿在我的目录中成功创建,但是当我尝试打开我的 excel 文件时,我收到类似 "Excel found unreadable content in workspace.xlsx".

的错误
public static void main(String args[]) throws InterruptedException{
        Workbook wb = new XSSFWorkbook();
        FileOutputStream fileOut;
        try {
            fileOut = new FileOutputStream("workbook.xls");
            wb.write(fileOut);
            fileOut.close();
            System.out.println("success");
        } catch (Exception e) {
            // TODO Auto-generated catch block
              System.out.println("failure");
            e.printStackTrace();
        }

}

我正在使用 excel 2010。

您的代码有两个错误 - 没有工作表(无效)和错误的扩展名 (XSSFWorkbook = .xlsx)

要创建一个新的空 Excel xlsx 文件,您的代码应该类似于:

Workbook wb = new XSSFWorkbook();
wb.createSheet();
FileOutputStream fileOut;
try {
     fileOut = new FileOutputStream("workbook.xlsx");
     wb.write(fileOut);
     fileOut.close();
     System.out.println("success");
 } catch (Exception e) {
     throw new RuntimeException("failure", e);
 }