小编Sum*_*ana的帖子

Apache poi创建错误的Excel文件

我正在使用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)

java apache excel swing apache-poi

3
推荐指数
1
解决办法
856
查看次数

标签 统计

apache ×1

apache-poi ×1

excel ×1

java ×1

swing ×1