简体   繁体   English

找不到符号Workbook.close()

[英]cannot find symbol Workbook.close()

I saw multiple questions with this header but didn't get my answer. 我看到了这个标题的多个问题,但没有得到我的答案。

 private void createHandBackFile(XSSFSheet sheet, String programId, XSSFWorkbook workbook) throws IOException {
    String output = "C:\\Users\\muddassirr\\Downloads\\Personal\\STORE\\Output";

    File file = new File(output + File.separator + programId);
    if (!file.exists()) {
        file.mkdirs();
    }
    int noOfColumns = sheet.getRow(0).getPhysicalNumberOfCells();
    for(int i = 0; i < noOfColumns; i++) {
        sheet.autoSizeColumn(i);
    }
    FileOutputStream outputStream = new FileOutputStream(new File(output + File.separator + programId + File.separator + "HAND_BACK.xlsx"));
    workbook.write(outputStream);
    outputStream.close();
    workbook.close();
}

There is no compilation error. 没有编译错误。 But As I run I get runtime error saying 但是当我运行时,我得到运行时错误说

java: cannot find symbol
symbol:   method close()
location: variable workbook of type org.apache.poi.xssf.usermodel.XSSFWorkbook

I got the answer. 我得到了答案。 This dependency was missing in pom.xml pom.xml中缺少此依赖项

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.17</version>
    </dependency>

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

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