Skip to content
Advertisement

xls file is corrupted after upgrading apache poi from version 4.0.1 to the latest versions ( version 4.1.2 and version 5.0.0)

The below code works fine with apache poi version 4.0.1 but after upgrading apache poi to the latest versions (version 4.1.2 or version 5.0.0) the xls file generated is corrupted and when i try to open it i cannot find any data inside. (the size of the xls file after upgrading the poi.jar was updated from 4KO to 0KO.)

import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

public abstract class ExcelExporter
{ 
    public static void exportPanel(String account, JTable table) {
        FileOutputStream excel = null;
        try {   
            Workbook wb = new HSSFWorkbook();
            Sheet sh = wb.createSheet("hello");
            Row row = sh.createRow(0);
            Cell cell = row.createCell(0);
            cell.setCellValue(1);
            excel = new FileOutputStream("WORKBOOK.xls");
            wb.write(excel);
            wb.close();
            excel.flush();
            excel.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }   
    }
}

Could you please advise? Thanks,

enter image description here enter image description here

Advertisement

Answer

Issue resolved by adding commons-math3.jar to my project.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement