写入.xlsx文件时出现POIXMLException

时间:2018-10-31 15:53:09

标签: java file apache-poi xlsx fileoutputstream

最近,我一直在尝试写入.xlsx文件。我的代码来自教程,在该教程中它工作得很好。就我而言不是。文件已创建,但没有名为“ Devnami”的工作表,也没有单词“发票”和“日期”。为什么会这样呢?我不知道这是否会更改某些内容,但我正在使用LibreOffice Calc处理.xlsx文件。这是我的代码:

private void gexcel() {
    // TODO Auto-generated method stub

    try {
        XSSFWorkbook workbook = new XSSFWorkbook();
        FileOutputStream out = new FileOutputStream(new File("C:\\Users\\CA_LTD\\Desktop\\excelfile.xlsx"));
        XSSFSheet Spreadsheet = workbook.createSheet("Devnami");
        Spreadsheet.getRow(1).createCell(0).setCellValue("invoice");
        Spreadsheet.getRow(1).createCell(1).setCellValue("date");
        workbook.write(out);
        out.close();

    }
    catch(Exception e) {
        System.out.println(e);
    }
    System.out.println("Excel file created");

}

这是堆栈跟踪:

org.apache.poi.ooxml.POIXMLException: org.apache.poi.ooxml.POIXMLException: java.lang.reflect.InvocationTargetException
Excel file created

0 个答案:

没有答案