Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 928
Muddassir Rahman Avatar asked Apr 14 '26 15:04

Muddassir Rahman


1 Answers

I got the answer. This dependency was missing in 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>
like image 128
Muddassir Rahman Avatar answered Apr 17 '26 21:04

Muddassir Rahman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!