File is corrupted after creating excel (.xlsx) file by using Apache POI with Java

后端 未结 2 2247
旧巷少年郎
旧巷少年郎 2021-02-14 21:25

I have created a Workbook/Excel in .xlsx format with Java using Apache POI API successfully. My code is as below that is created a file named \"RiponAlWasim.xlsx\" in D drive:

2条回答
  •  独厮守ぢ
    2021-02-14 21:35

    It needs to be added at least one sheet to the workbook. So, after creating a worksheet the following code is working well:

    Workbook wb = new XSSFWorkbook();
    Sheet sheet1 = wb.createSheet("Ripon");
    FileOutputStream fileOut = new FileOutputStream("D:\\RiponAlWasim.xlsx");
    wb.write(fileOut);
    fileOut.close();
    wb.close();
    

提交回复
热议问题