How to convert Legacy XLS to CSV in PHP

Cloudmersive
2 min readApr 24, 2020

--

Nothing like legacy file formats to ruin your day. It’s time to put an end to that, because in today’s tutorial I am going to explain a very easy method for converting the old XLS format into a more useful CSV. Let’s dive in.

Client installation comes first. We will get this done by running this command for composer.

composer require cloudmersive/cloudmersive_document_convert_api_client

Next is the call of our function convertDocumentXlsToCsv:

<?phprequire_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\ConvertDocumentApi(// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.// This is optional, `GuzzleHttp\Client` will be used as default.new GuzzleHttp\Client(),$config);$input_file = "/path/to/file"; // \SplFileObject | Input file to perform the operation on.try {$result = $apiInstance->convertDocumentXlsToCsv($input_file);print_r($result);} catch (Exception $e) {echo 'Exception when calling ConvertDocumentApi->convertDocumentXlsToCsv: ', $e->getMessage(), PHP_EOL;}?>

With those preliminaries out of the way, it’s as simple as inputting the XLS file and awaiting the results. Without a doubt, this is the easiest method for setting up this functionality.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet