2017 © Pedro Peláez
 

library eximport

Library to easily validate and import Excel data

image

lezhnev74/eximport

Library to easily validate and import Excel data

  • Monday, June 13, 2016
  • by lezhnev74
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Build Status Latest Stable Version License Total Downloads composer.lock, (*1)

Eximporter

Object oriented Excel importer with input validation It lets you to import any excel file, validate each cell and do your business logic with good and failed ones., (*2)

P.s. It will automatically skip rows with all nulls in cells., (*3)

Preview, (*4)

Example

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' => 'required',
        // you can set manual closures as rules (as an array)
        'amount'      => ['custom_rule' => function($cellvalue){ return $cell_value > 100; }]
         // you can add few rules in a row
         'title'      => [
                'required|regexp:#^[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: required
            // ...
        }
    });

    // set handlers for good rows
    $importer->setHandlerForGoodRow(function ($row) {
        // business logic with $row
    });


    // ok let's go
    $importer->read();

    // you can access counters
    echo $importer->getGoodRowsCount();
    echo $importer->getBadRowsCount();

} catch (BadFile $e) {
    // unable to open this file
}




Usage

This package is intended to be used in projects with Excel import functions. It let's you easily add a validation layer and filtering options for your data. It is based on PHPOffice/PHPExcel under the hood., (*5)

Installation

composer require lezhnev74/eximport

Requirements: * PHP7 * PHP extension php_zip enabled * PHP extension php_xml enabled * PHP extension php_gd2 enabled (if not compiled in) * (read more)[https://github.com/PHPOffice/PHPExcel/wiki/Developer-Documentation-Prerequisites], (*6)

Credits

Dmitriy Lezhnev lezhnev.work@gmail.com, (*7)

The Versions

13/06 2016

dev-master

9999999-dev

Library to easily validate and import Excel data

  Sources   Download

MIT

The Requires

 

The Development Requires

13/06 2016

1.0

1.0.0.0

Library to easily validate and import Excel data

  Sources   Download

MIT

The Requires

 

The Development Requires