How to validate an Excel XLSX Spreadsheet in Salesforce Apex

Cloudmersive
1 min readFeb 15, 2020

--

In this tutorial, we are going to show you just how easy it is to perform validation upon Excel files using Apex.

First, download our Apex API Client and unzip it. Then copy the contents into your project folder.

Then call validateDocumentXlsxValidation, with your XLSX as the inputFile:

SwagValidateDocumentApi api = new SwagValidateDocumentApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'inputFile' => Blob.valueOf('Sample text file\nContents')};try {// cross your fingersSwagDocumentValidationResult result = api.validateDocumentXlsxValidation(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

And now the API will respond to us in this format here:

{
"DocumentIsValid": true,
"ErrorCount": 0,
"WarningCount": 0,
"ErrorsAndWarnings": [
{
"Description": "string",
"Path": "string",
"Uri": "string",
"IsError": true
}
]
}

Done!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet