renekorss / phpexcelformatter
PHPExcelFormatter is class to make it more simple to get data from Excel documents.
Installs: 2 952
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 5
Forks: 2
Open Issues: 0
Requires
- php: ^7.2
- phpoffice/phpspreadsheet: ^1.14
Requires (Dev)
- cedx/coveralls: ^11.2
- friendsofphp/php-cs-fixer: ^2.16
- phpmd/phpmd: ^2.8
- phpunit/phpunit: ^8.5
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-11-16 20:48:25 UTC
README
PHPExcelFormatter
PHPExcelFormatter is class to make getting data from Excel documents simpler.
- Read columns what you really need
- Set column names for documents what dosen't have column names on first row
- Set your DB field names for columns
- Retrieve data in array or MySQL query format
- Greate for importing files and then letting user to connect document columns with your DB fields :) (example coming)
Install
composer require renekorss/phpexcelformatter
Usage
// Require needed files require __DIR__ . '/vendor/autoload.php'; use RKD\PHPExcelFormatter\PHPExcelFormatter; use RKD\PHPExcelFormatter\Exception\PHPExcelFormatterException; try { // Load file $formatter = new PHPExcelFormatter('example1.xls'); // Output columns array (document must have column names on first row) $formatterColumns = array( 'username' => 'username', 'phone' => 'phone_no', 'email' => 'email_address' ); // Output columns array (document dosen't have column names on first row) // Skip fourth column (age) (third in array), because we don't need that data // NOTE: if document dosen't have column names on first line, second parameter for PHPExcelFormatter should be $readColumns = false, otherwise it will skip first line of data $formatterColumns = array( 'username', 'email_address', 'phone', 4 => 'sex' ); // Set our columns $formatter->setFormatterColumns($formatterColumns); // Output as array $output = $formatter->output('a'); // OR // $output = $formatter->output('array'); // Print array echo '<pre>'.print_r($output, true).'</pre>'; // Set MySQL table $formatter->setMySQLTableName('users'); // Output as mysql query $output = $formatter->output('m'); // OR // $output = $formatter->output('mysql'); // Print mysql query echo '<pre>'.print_r($output, true).'</pre>'; } catch (PHPExcelFormatterException $e) { echo 'Error: '.$e->getMessage(); }
View examples
License
PHPExcelFormatter is licensed under MIT