Search code examples
javaexcelvisual-studio-codeapache-poi

Error in using Apache.poi for reading an excel sheet in Java, using VScode


I am a beginner in coding, and want to read an excel file (xlsx) using java. My IDE is VSCode and I'm not using maven or gradle.

I downloaded the zip file from the Apache website, poi-bin-5.2.3, and put the jar files (poi-5.2.3.jar, poi-ooxml-5.2.3.jar) in the "Referenced Libraries" section.

But when I include the line :

import org.apache.poi.ss.usermodel.*;

I get the error:

error: package org.apache.poi.ss.usermodel does not exist

I am a beginner at coding and this is my first time importing jar files and trying to use Apache, so please explain things at a very basic level.


Solution

  • 1.unzip poi-bin-5.2.3.zip.

    2.Create a lib folder in the folder I opened a folder on vscode.

    3.Put the unzip folder inside lib.

    JavaProject
    ├───ReadExcelFileDemo.java
    └───lib
        └───poi-bin-5.2.3
    

    4.You also need to install log4j-core.jar.

    A simple way: Download the corresponding version through a default empty Maven project. Then copy the downloaded folder into lib folder.

    Default location:

    "C:\Users\<username>\.m2\repository\org\apache\logging\log4j\log4j-core\2.18.0"
    

    pom.xml

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.18.0</version>
    </dependency>
    

    There is an error in the code sample. Replace

    case Cell.CELL_TYPE_STRING: -> case STRING:

    case Cell.CELL_TYPE_NUMERIC: -> case NUMERIC: