0

I am trying to applied Apache POI on my Linux system, using IntelliJ. I have downloaded jar files from Apache POI site, for windows (I couldn't find any for Linux, there are options for Mac and Windows only) and I wrote a code to retrieve data from *.xlsx spreadsheet:

String path = "/home/razz/Documents/test01.xlsx";
FileInputStream fileInputStream = new FileInputStream(path);
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(fileInputStream); // musimy add exception
Sheet sheet = xssfWorkbook.getSheet("Sheet1");

Row row = sheet.getRow(0);
System.out.println(row);

But I am receiving an error

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
<xml-fragment r="1" customFormat="false" ht="12.8" hidden="false" customHeight="false" outlineLevel="0" collapsed="false" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:main="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <main:c r="A1" s="0" t="s">
    <main:v>0</main:v>
  </main:c>
  <main:c r="B1" s="0" t="s">
    <main:v>1</main:v>
  </main:c>
</xml-fragment>

Process finished with exit code 0

I cannot find any tutorial how to make it work.

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
Adam
  • 1
  • 1
  • 1
    What `apache poi` version have you downloaded and from where? As the error tells, you need [log4j-core](https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core). For last `apache poi 5.2.2` it is `log4j` version `2.17.2`. For download `apache poi 5.2.2` see https://poi.apache.org/download.html#POI-5.2.2. – Axel Richter Apr 10 '22 at 10:57
  • poi-bin-5.2.2-20220312.zip (57 MB, signature (.asc), checksum: SHA-256, SHA-512) this one, from the official site. – Adam Apr 10 '22 at 10:59
  • https://i.imgur.com/slAclJA.png those are the files inside the *.zip package – Adam Apr 10 '22 at 11:00
  • @AxelRichter can you please direct me what should I do with code for log4j? Where should I insert it? – Adam Apr 10 '22 at 11:02
  • 1
    Simply put [log4j-core-2.17.2.jar](https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core/2.17.2) in class path while compiling and running. – Axel Richter Apr 10 '22 at 11:04
  • Ok so now I am not getting an error, but instead of the data from the spreadsheet i have only this https://i.imgur.com/Gr8SUla.png – Adam Apr 10 '22 at 11:07
  • 1
    What you get is the `row.toString()` which shows the XML of the `CTRow` behind the `XSSFRow`. What else do you expect from `System.out.println(row);`? See [Getting the cell contents](https://poi.apache.org/components/spreadsheet/quick-guide.html#CellContents). Also reading whole [Busy Developers' Guide to HSSF and XSSF Features](https://poi.apache.org/components/spreadsheet/quick-guide.html) is of interrest. – Axel Richter Apr 10 '22 at 11:14
  • I promise you I will read it all, but I need this to work now, because I start school in an hour... Can you please show the simple solution? I will understand the logic behind this ASAP – Adam Apr 10 '22 at 11:16
  • https://stackoverflow.com/questions/7608511/java-poi-how-to-read-excel-cell-value-and-not-the-formula-computing-it/71390145#71390145 – Axel Richter Apr 10 '22 at 11:19
  • 2
    None of the downloads on the Apache POI site is specific to Windows, macOS or Linux in any way. – Mark Rotteveel Apr 10 '22 at 11:31
  • @AxelRichter it is working, thank you so much! My question is do I have to use those 2 loops each time I want a value from the file? – Adam Apr 10 '22 at 11:34
  • @AxelRichter I am totally green in Java, started the course like 3 months ago, but I managed to get what I wanted even without dataFormator. Thank you so much for your help! – Adam Apr 10 '22 at 11:49

0 Answers0