DEV Community

CodeSharing
CodeSharing

Posted on

2 2

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)

Installation
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.

<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls.free</artifactId>
        <version>3.9.1</version>
    </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

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
        wb.loadFromFile("report.xlsx");

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

            //Get worksheets names
            String sheetName = ((Worksheet) sheet).getName();
            System.out.println(sheetName);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Alt Text

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more