PHP code example of spyck / spreadsheet
1. Go to this page and download the library: Download spyck/spreadsheet 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/ */
spyck / spreadsheet example snippets
declare(strict_types=1);
use Spyck\Spreadsheet\Csv;
* banana;20
* pear;10
* melon;4
*/
$csv = new Csv();
$csv->setGzip(true);
$csv->setFilter(function (array $data): bool {
return $data['count'] > 10;
});
$result = $csv->getResult('test.csv.gz', [
'name',
'count',
]);
print_r ($result->getData());
/**
* Result:
*
* [
* 'name' => 'apple',
* 'count' => '15',
* ],
* [
* 'name' => 'banana',
* 'count' => '20',
* ];
*/
$csv = new Csv();
$csv->setGzip(true);
$csv->setCallback(function (array $data): ?array {
$data['name'] = ucfirst($data['name']);
return $data;
});
$csv->setFilter(function (array $data): bool {
return $data['count'] > 10;
});
$result = $csv->getResult('test.csv.gz', [
'name',
'count',
]);
print_r ($result->getData());
/**
* Result:
*
* [
* 'name' => 'Apple',
* 'count' => '15',
* ],
* [
* 'name' => 'Banana',
* 'count' => '20',
* ];
*/
$csv = new Csv();
$csv->setGzip(true);
$csv->setEof(function (array $data, int $index): bool {
return 'banana' === $data['name'];
});
$result = $csv->getResult('test.csv.gz', [
'name',
'count',
]);
print_r ($result->getData());
/**
* Result:
*
* [
* 'name' => 'apple',
* 'count' => '15',
* ];
*/
print $result->getTotal();
/**
* Result:
*
* 1
*/