How to Convert Excel (XLSX) to a JSON Object Array with Java

Many of us are familiar with XLSX file extensions from working extensively in Excel. As ubiquitous as that format may be, it leaves much to be desired when it comes to interoperability with other platforms and systems. Thankfully, JSON is one of the most interoperable formats out there, and with our XLSX to JSON conversion API, you can make that transition in an instant whenever the need arises. Below, we’ll walk through how you can take advantage of this API & structure your API call in Java.

We will start by installing the Java SDK with Maven. First, include a reference in the pom.xml repository:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Then add one to the pom.xml dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

Next add the import classes to the top of your file, and call the API:

// 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.ConvertDataApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth 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");
ConvertDataApi apiInstance = new ConvertDataApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
try {
byte[] result = apiInstance.convertDataXlsxToJson(inputFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDataApi#convertDataXlsxToJson");
e.printStackTrace();
}

Nice and easy, right? Make sure you have the following parameters satisfied, and you’re good to go (no further code required):

  1. Your input file to perform the operation on
  2. Your Cloudmersive API key (this can be obtained by registering a free account on our website, www.cloudmersive.com)

--

--

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
Cloudmersive

Cloudmersive

437 Followers

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