简体   繁体   English

使用jExcel创建Excel文件

[英]Create Excel File Using jExcel

I made an excel file using jExcel API, but when I tried to open that file I got error filename.xls:file format is not valid and I can not open this file, here is my Java code 我使用jExcel API制作了一个excel文件,但是当我尝试打开该文件时,出现错误filename.xls:file格式无效,并且无法打开此文件,这是我的Java代码

File file = new File("C:\\Users\\Giga\\Desktop\\yvela.xls");
    WritableWorkbook wb = Workbook.createWorkbook(file);

    WritableSheet wsheet = wb.createSheet("First Sheet", 0);

    int row = 0;

    for (Student student : students) {
        wsheet.addCell(new Label(0, row, student.getName()));
        wsheet.addCell(new Label(1, row, student.getSurname()));
        row++;
    }

    wb.close();

You need to call wb.write() before wb.close() . 您需要在wb.write()之前调用wb.close()

The write method finalizes some things and actually writes the data to the file. write方法完成一些操作,然后将数据实际写入文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM