PHP code example of lekoala / spread-compat

1. Go to this page and download the library: Download lekoala/spread-compat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lekoala / spread-compat example snippets


SpreadCompat::$preferredCsvAdapter = SpreadCompat::NATIVE; // our native csv adapter is the fastest
SpreadCompat::$preferredXlsxAdapter = SpreadCompat::NATIVE; // our native xlsx adapter is the fastest

$data = iterator_to_array(SpreadCompat::read('myfile.csv'));

// or
foreach(SpreadCompat::read('myfile.csv') as $row) {
    // Do something
}

SpreadCompat::output('myfile.csv');
exit();

$data = iterator_to_array(SpreadCompat::read('myfile.csv', assoc: true));

// or
$data = iterator_to_array(SpreadCompat::read('myfile.csv', ...$opts));

$options = new Options();
$options->separator = ";";
$data = iterator_to_array(SpreadCompat::read('myfile.csv', $options));

$csvData = SpreadCompat::readString($csv, adapter: SpreadCompat::NATIVE);
// or
$options = new Options();
$options->adapter = SpreadCompat::NATIVE;
$csvData = SpreadCompat::readString($csv, $options);