maymeow / excel-importer
A php package to transform XLSX filse to models.
Installs: 1 056
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 1
Type:php-pacakge
Requires
- php: 8.*
- meow/hydrator: ^1.0
- phpoffice/phpspreadsheet: ^1.13
- symfony/console: ^5.1
Requires (Dev)
- phpstan/phpstan: ^1.1
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2024-12-18 20:17:38 UTC
README
Simple and extendable library for loading data from Excel files (.xlsx) into objects.
This Library using phpoffice/phpspreadsheet
to read from XLSX files. Look at their Github
Read files - commandline with example data (Deprecated)
From command line with example data
php application.php app:read-file -f ./path/to/file.xlsx
Via Source Code
Create new model which extending MayMeow\ExcelImporter\Models\BaseModel
. To map column from excel to property use
\MayMeow\ExcelImporter\Attributes\Column
attribute.
<?php use MayMeow\ExcelImporter\Models\BaseModel; class ExampleModel extends BaseModel { #[\MayMeow\ExcelImporter\Attributes\Column('A')] protected string $property; public function getProperty() { return $this->property; } }
read from file following example is reading from active sheet
// ... use MayMeow\ExcelImporter\Models\ExampleModel; use MayMeow\ExcelImporter\Writers\ModelWriter; use PhpOffice\PhpSpreadsheet\Reader\Xlsx; // ... public function testImportingFile() { $xlsxReader = new Xlsx(); $spreadsheet = $xlsxReader->load((new TestingDataLocator())->locateExcelFile()); $writer = new ModelWriter(); /** @var array<TestingModel> $modelArray */ $modelArray = $writer->write(TestingModel::class, $spreadsheet); } // ...
Files
For getting path to files you can create Locator by implementing MayMeow\ExcelImporter\Tools\FileLocatorInterface
which
is not required by XLS reader but recommended.
License MIT