Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count number of worksheets in Excel File

How to count number of worksheets in a Microsoft Excel file using Java SE?

like image 239
Shumon Saha Avatar asked Dec 27 '22 16:12

Shumon Saha


2 Answers

There's no standard class/library files in Java SE that interfaces with MS Excel. In Apache POI, you can use HSSFWorkbook.getNumberOfSheets() method which returns you the number of worksheet from a workbook.


To open an Excel file and get HSSFWorkbook, do this:

String fileName = "C://Excel.xls";
POIFSFileSystem fileSystem = new POIFSFileSystem(new FileInputStream(fileName));
HSSFWorkbook workbook = new HSSFWorkbook(fileSystem);
like image 199
Buhake Sindi Avatar answered Dec 30 '22 05:12

Buhake Sindi


Use getNumberOfSheets() in the WritableWorkbook class.

Take a look at these:

jxl.Workbook;
jxl.write.Label;
jxl.write.WritableSheet;
jxl.write.WritableWorkbook;

http://jexcelapi.sourceforge.net/resources/javadocs/2_6_10/docs/jxl/write/WritableWorkbook.html

like image 43
Sherif elKhatib Avatar answered Dec 30 '22 05:12

Sherif elKhatib