Aaron Ferguson Aaron Ferguson - 5 months ago 13
Java Question

How Do I Create a New Excel File Using JXL?

I'm trying to create a new Excel file using jxl, but am having a hard time finding examples in their API documentation and online.

Answer

After messing around awhile longer I finally found something that worked and saw there still wasn't a solution posted here yet, so here's what I found:

try {
    String fileName = "file.xls";
    WritableWorkbook workbook = Workbook.createWorkbook(new File(fileName));
    workbook.createSheet("Sheet1", 0);
    workbook.createSheet("Sheet2", 1);
    workbook.createSheet("Sheet3", 2);
    workbook.write();
    workbook.close();
} catch (WriteException e) {

}
Comments