How to get worksheets from an Excel XLSX spreadsheet in Java

If you have ever tried to parse an Excel spreadsheet yourself, you probably know how complicated they really are. Simply obtaining worksheet names from an XLSX file can be quite challenging, as you have to dive through multiple layers of formatting limbo to find your desired information. To make things much simpler, today’s tutorial will use an API to get this done for you in a fraction of the time.

We begin with a reference to jitpack in our respositories.


Then our dependency reference for the Cloudmersive API client.


And finally, our function call, which looks like this here:

// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.EditDocumentApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");EditDocumentApi apiInstance = new EditDocumentApi();GetXlsxWorksheetsRequest input = new GetXlsxWorksheetsRequest(); // GetXlsxWorksheetsRequest | Document input requesttry {GetXlsxWorksheetsResponse result = apiInstance.editDocumentXlsxGetWorksheets(input);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling EditDocumentApi#editDocumentXlsxGetWorksheets");e.printStackTrace();}


Image for post
Image for post

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store