How to convert Excel XLSX to CSV Files in Salesforce Apex

Cloudmersive
1 min readFeb 16, 2020

--

Need an easy method for converting XLSX into CSV? Look no further! We’ve got you covered.

To start things off, download and extract our API client into the folder of your Apex project.

Now all that’s left is to use convertDocumentXlsxToCsv on your Excel file:

SwagConvertDocumentApi api = new SwagConvertDocumentApi();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'),'outputEncoding' => 'outputEncoding_example'};try {// cross your fingersBlob result = api.convertDocumentXlsxToCsv(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

Our API will now do the heavy lifting for us and return our file in CSV form. There is also a similar function called that is compatible with the older XLS format.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

Responses (1)