我正在使用 apache.poi 制作一个 excel 文件,但是当我尝试使用 Microsoft Excel 打开时使用简单的 java 代码生成它时,它说无法打开该文件,因为我的文件格式或扩展名无效。
我正在使用最新的 poi 和 Micrisoft Office 2019 32 位。
package com.company;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class Main {
public static void main(String[] args) throws FileNotFoundException, IOException{
Workbook wb = new HSSFWorkbook();
// An output stream accepts output bytes and sends them to sink.
OutputStream fileOut = new FileOutputStream("Geek.xlsx");
// Creating Sheets using sheet object
Sheet sheet1 = wb.createSheet("Array");
Sheet sheet2 = wb.createSheet("String");
Sheet sheet3 = wb.createSheet("LinkedList");
Sheet sheet4 = wb.createSheet("Tree");
Sheet sheet5 = wb.createSheet("Dynamic Programing");
Sheet sheet6 = wb.createSheet("Puzzles");
System.out.println("Sheets Has been Created successfully");
wb.write(fileOut);
}
}
我构建了它,工作正常,但它生成了一个错误的文件!我可能做错了什么?