akeneo-labs / spreadsheet-parser
Akeneo Spreadsheet parser. Reads XLXS files from Microsoft Excel and Open Office
Installs: 527 913
Dependents: 6
Suggesters: 0
Security: 0
Stars: 146
Watchers: 24
Forks: 50
Open Issues: 18
Requires
- php: >=5.4.0
- symfony/options-resolver: ~2.6 || ~3.0 || ^4.0
Requires (Dev)
- phpspec/phpspec: ~2.0
- symfony/phpunit-bridge: ^4.2
README
This component is designed to extract data from spreadsheets, while being easy on resources, even for large files.
The current version of the spreadsheet parser works with csv and xlsx files.
Installing the package
From your application root:
$ php composer.phar require --prefer-dist "akeneo-labs/spreadsheet-parser"
Usage
To extract data from an XLSX spreadsheet, use the following code:
use Akeneo\Component\SpreadsheetParser\SpreadsheetParser; $workbook = SpreadsheetParser::open('myfile.xlsx'); $myWorksheetIndex = $workbook->getWorksheetIndex('myworksheet'); foreach ($workbook->createRowIterator($myWorksheetIndex) as $rowIndex => $values) { var_dump($rowIndex, $values); }
By using the CSV parser options, you can specify the format of your CSV file :
use Akeneo\Component\SpreadsheetParser\SpreadsheetParser; $workbook = SpreadsheetParser::open('myfile.csv'); $iterator = $workbook->createRowIterator( 0, [ 'encoding' => 'UTF-8', 'length' => null, 'delimiter' => ',', 'enclosure' => '"', 'escape' => '\\' ] ); foreach ($workbook->createRowIterator(0) as $rowIndex => $values) { var_dump($rowIndex, $values); }
Running the tests
To run unit tests, use phpspec:
$ php bin/phpspec run
To run integration tests, use phpunit:
$ phpunit