How to convert Excel XLSX to CSV Files in PHP

Let’s take the pain out of file conversion in two easy steps.

First, add the Convert API to your library like so:

"require": {
"cloudmersive/cloudmersive_document_convert_api_client": "^1.4",
}

Second, call the desired function, in this case convertDocumentXlsxToCsv:

<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\ConvertDocumentApi(


new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/file"; // \SplFileObject | Input file to perform the operation on.
try {
$result = $apiInstance->convertDocumentXlsxToCsv($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ConvertDocumentApi->convertDocumentXlsxToCsv: ', $e->getMessage(), PHP_EOL;
}
?>

Boom! Done! If you need to convert a CSV back into XLSX, it’s as simple as calling the appropriate function. Our Convert API comes equipped with support for a wide variety of other file types, including DOCX and JSON, so be sure to check out what it can do.

Written by

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