Skip to content

vdbf/import-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

import-php

Build Status Code Coverage Scrutinizer Code Quality

Simple importer written in PHP

Example

<?php

/**
 * Excel sheet example:
 * | A | B | C |
 * | 1 | 2 | 3 |
 * | 4 | 5 | 6 |
 */

$path = 'path/to/file.xlsx';
$importer = new Vdbf\Import\Excel\SingleSheetImporter(new Vdbf\Import\Excel\Reader());

//importer closure is called for every data-row
$importer->import($path, function ($row, $header) {
  print_r($header); //['A', 'B', 'C']
  print_r($row); //[1, 2, 3]
});

//importer dump method dumps all rows to a 2D associative array
$dump = $importer->dump($path);
print_r($dump) //[['A' => 1, 'B' => 2, 'C' => 3], ['A' => 4, 'B' => 5, 'C' => 6]]

Configuration

The importer can be constructed with an array of options as a second argument.

<?php

$options = [
  'read_header' => false, //skips reading the first row as a header row, defaults to true
  'sheet_index' => 1      //imports the second sheet, defaults to 0
];

$importer = new Vdbf\Import\Excel\SingleSheetImporter(new Vdbf\Import\Excel\Reader(), $options);

...

About

Simple importer written in PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages