How to convert Excel XLSX to CSV Files in PHP
1 min readJul 31, 2019
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.