A
A
Alexander Koshelev2021-09-07 21:23:01
Java
Alexander Koshelev, 2021-09-07 21:23:01

Why is the sheet not being created in Excel (apach poi)?

Good evening.
I try Apache Poi, the file can be created, but the sheets are not in any.
Here is a link to the docks I use (the new sheet section is almost at the very top)
https://poi.apache.org/components/spreadsheet/quic...
Here is my code:

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Main {
    public static void main(String[] args) {
        Workbook wb = new HSSFWorkbook();  // or new XSSFWorkbook();
        Sheet sheet = wb.createSheet("fhgfgh");
        OutputStream file = null;
        try {
            file = new FileOutputStream("111.xls");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            wb.write(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

And here are a bunch of errors, but at the same time, the excel file itself is created with one sheet whose name is equal to the name of the file itself
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/util/ArithmeticUtils
at org.apache.poi.poifs.property.RootProperty.setSize(RootProperty.java:59)
at org.apache.poi .poifs.property.DirectoryProperty.(DirectoryProperty.java:52)
at org.apache.poi.poifs.property.RootProperty.(RootProperty.java:31)
at org.apache.poi.poifs.property.PropertyTable.(PropertyTable. java:58)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.(POIFSFileSystem.java:99)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.(POIFSFileSystem.java:121)
at org.apache.poi .hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1357)
at Main.main(Main.java:22)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.util.ArithmeticUtils
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal. loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 8 more

Please help me figure out what the problem is!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Roo, 2021-09-08
@xez

It looks like the problem is that the org.apache.commons package is missing, which the apache.poi library needs. Master
maven - the problem will be solved by itself

E
Egor Khombak, 2021-09-14
@Khombachke

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/util/ArithmeticUtils

Most likely a problem with missing packages. Try adding a dependency on Apache Commons Math
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-math3</artifactId>
    <version>3.6.1</version>
</dependency>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question