How to convert Excel XLSX to CSV Files in Salesforce Apex

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.

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