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>
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); } } }
Top comments (0)