使用java创建XLSX文件后出现错误消息

时间:2014-12-30 19:21:59

标签: java excel apache-poi xlsx

我正在使用apache poi使用java创建一个简单的xlsx文件,如下所示

    String date = "2014/12/29";
    XSSFWorkbook  w = ADPFidessa.createExcelWorkbook(date);
    response.reset();
    response.setContentType("application/xlsx");
    response.setHeader("Content-Disposition", "attachment;filename=ADP_Fidessa.xlsx");
    w.write(response.getOutputStream());

这是createExcelWorkbook方法

public static XSSFWorkbook createExcelWorkbook(String sBsnsDt) throws Exception
   {
    // create a new file
    FileOutputStream out = new FileOutputStream("workbook.xlsx");

    // create a new workbook
    XSSFWorkbook wb = new XSSFWorkbook();
    // create a new sheet
    XSSFSheet s = wb.createSheet("Sheet1");

    // declare a row object reference
    XSSFRow r;
    // declare a cell object reference
    XSSFCell c;

    ArrayList<ADPFidessa> aDADPFidessalist=null;
    ADPFidessaDAO adpfiddao = new ADPFidessaDAO();
    aDADPFidessalist=adpfiddao.showADPFid(sBsnsDt);      

    int rownum;
    // header row and columns
    r = s.createRow(0);

    c = r.createCell(0);
    c.setCellValue("Business Date");

    c = r.createCell(1);
    c.setCellValue("ID");

    c = r.createCell(2);
    c.setCellValue("Ant");

    c = r.createCell(3);
    c.setCellValue("Sol");

    c = r.createCell(4);
    c.setCellValue("itions");

    c = r.createCell(5);
    c.setCellValue(sition");

    c = r.createCell(6);
    c.setCellValue("ffere");

    c = r.createCell(7);
    c.setCellValue("Age");

    rownum = 1;
    for (ADPFidessa di : aDADPFidessalist)
    {

     r = s.createRow(rownum);
     c = r.createCell(0);
     c.setCellValue(di.getBusinessDate());

     c = r.createCell(1);
     c.setCellValue(di.getkId());

     c = r.createCell(2);
     c.setCellValue(di.getAnt());

     c = r.createCell(3);
     c.setCellValue(di.getSol());

     c = r.createCell(4);
     c.setCellValue(di.getition());


     c = r.createCell(5);
     c.setCellValue(di.getsition());

     c = r.createCell(6);
     c.setCellValue(di.getffere());
     c = r.createCell(7);
     c.setCellValue(di.getAge());


     rownum++;
    } 

    try {
        wb.write(out);
        out.close();
    } catch (Exception e) {
        System.out.println("Error");
        System.out.println(e);
    }
    return wb;
   }

方法showADPFid(sBsnsDt);返回正确的值并正确保存输出文件。这是问题所在。当我尝试在MS Excel中打开文件时,它显示错误消息

enter image description here

现在,点击“是”后,excel文件将打开,所有数据都按预期存在。但是,会出现另一个对话框

enter image description here

日志文件显示

enter image description here

任何人都可以对这个错误有任何想法吗?如何解决这个问题?

感谢

编辑:还有,这是我的导入

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.util.*;

0 个答案:

没有答案