Home » excel » Excel found unreadable content in workspace.xlsx (POI – java)

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

Posted by: admin March 9, 2020 Leave a comment

Questions:

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.

How to&Answers:

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