Get Excel Worksheets Names using Java

When you want to find the specific worksheet quickly from several Excel workbooks that containing a lot of data, you may need to get the names of these worksheets first. This article will introduce a time-saving method to get worksheets names without opening the workbook. (API: Free Spire.XLS for Java)

Method 1: Download the free API and unzip it, then add the Spire.Xls.jar file to your project as dependency.

Method 2: You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.


Relevant Code Snippet

import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class GetWorksheetName {
public static void main(String[] args) {

//Create a Workbook object
Workbook wb = new Workbook();

//Load a sample Excel file

//Loop through the worksheets
for (Object sheet: wb.getWorksheets()
) {

//Get worksheets names
String sheetName = ((Worksheet) sheet).getName();

Sharing Java Code