Apache poi创建错误的Excel文件

Sum*_*ana 3 java apache excel swing apache-poi

我正在使用Apache_poi制作Excel文件.此文件将在我的Swing应用程序中的按钮的操作事件上创建.Excel工作表创建得很好但是,当我打开它时,我收到此错误:

您尝试打开的文件格式与文件扩展名指定的格式不同

当我打开文件时它完全是空的.

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try {
        // String personalclass=jComboBox1.getSelectedItem().toString();
        // String ac="academic";
        // FileOutputStream output=new FileOutputStream("D:\\"+personalclass+ac+".xls");
        FileOutputStream output=new FileOutputStream("D:\\workbook.xls");
        Workbook wb=new HSSFWorkbook();
        Sheet sheet =wb.createSheet("Class 1"); 
        Cell cell=sheet.createRow(0).createCell(3);
        cell.setCellValue("Thisisatestofmerging");
        //sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
        output.close();
    }
    catch(Exception e)
    {
    }
}  
Run Code Online (Sandbox Code Playgroud)

Jon*_*eau 5

你忘了打电话write给你Workbook.

在关闭流之前添加此行:

      wb.write(output);
Run Code Online (Sandbox Code Playgroud)