简体   繁体   中英

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

I'm trying to create a workbook from java code. I'm using POI library for this, after executing the program, workbook is successfully creating in my directory, But when i'm trying open my excel file im getting error like "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();
        }

}

I'm using excel 2010.

Your code is making two mistakes - no sheets (not valid), and wrong extension (XSSFWorkbook = .xlsx)

To create a new empty Excel xlsx file, your code should instead be something like:

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);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM