PHP code example of lezhnev74 / eximport
1. Go to this page and download the library: Download lezhnev74/eximport 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/ */
lezhnev74 / eximport example snippets
use Eximporter\Eximporter;
use Eximporter\Exceptions\BadFile;
$file = "./tests/resources/test_05.xlsx";
try {
$importer = new Eximporter($file);
$importer->setValidationRules([
// you can set rules by names
'description' => '#^[0-9]+$#',
[
'custom_rule_2' => function($cell_value) { return strlen($cell_value)<10; }
]
],
]);
// set handlers (closures) to handle each good or bad (validation failed) row
$importer->setHandlerForBadRow(function ($row, $bad_cells) {
foreach ($bad_cells as $cell_title => $validation_result) {
echo $cell_title . " failed validators: " . implode(", ", $validation_result->getFailed());
echo "\n";
// example output:
// Amount failed validators: custom1
// Description failed validators: