[英]Excel found unreadable content in workspace.xlsx (POI - java)
我正在嘗試從Java代碼創建工作簿。 我為此使用POI庫,執行該程序后,工作簿已成功在我的目錄中創建,但是當我嘗試打開excel文件時,出現錯誤,例如“ Excel在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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.