How to Convert XLSX (Excel) to XML with Java
Moving spreadsheets around using Excel’s native XLSX format is notoriously difficult, as the format is proprietary and lacks interoperability. When it comes to moving data from one program to another, formats like JSON and XML are much better options — especially the latter when there are complicated interchange requirements in a given application. With our XLSX to XML conversion API, you can make that format transition in an instant and build it into your application as a cloud service. Below, we’ll walk through how to take advantage of this API by structuring your API call with ready-to-run code blocks in Java.
To kick things off, let’s start by installing the Java SDK with Maven. Add a reference to the pom.xml repository:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then add a reference to the pom.xml dependency:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
With installation all wrapped up, let’s now add the import classes and then complete the API call. First, make sure the following parameters are satisfied:
- Your input XLSX file for the operation
- Your Cloudmersive API key (missing one of these? just head to our website and register a free account — you’ll get a limit of 800 API calls per month, and access to dozens of additional Cloudmersive utility APIs).
// 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.convertDataXlsxToXml(inputFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertDataApi#convertDataXlsxToXml");
e.printStackTrace();
}