D
D
dnpgk2020-03-10 12:56:38
Java
dnpgk, 2020-03-10 12:56:38

How to check if a sheet exists in an Excel file (Apache POI)?

In the If statement, I check if the Excel file exists in order to open it and perform a series of actions, but apart from checking the existence of the file itself, how can I immediately add a check for the existence of a sheet (sheet) in this file under a certain index or name. I give the existing code below:

File b = new File(getExternalFilesDir(null) + "/plik.xls");
                if (b.exists()) {  
                    File file = new File(getExternalFilesDir(null) + "/plik.xls");
                    try {
                        FileInputStream inputStream = new FileInputStream(file);.....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cheypnow, 2020-03-10
@dnpgk

https://poi.apache.org/apidocs/dev/org/apache/poi/... - returns leaf by index. - returns a sheet by name.
Sheet getSheetAt(int index)
Sheet getSheet(java.lang.String name)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question