0

i would like to know how can i use PhpSpreadsheet symfony 3 , should i use this bundle : roromix/SpreadsheetBundle, can i have a little exemple how to use it to read rows from exemple_file.xlst

thank you

1 Answers1

1

I would advice to use the PHPSpreadsheet package directly.

$spreadsheet = PhpSpreadsheet\IOFactory::load('exemple_file.xlst' );
$worksheet = $spreadsheet->getActiveSheet();  // get active worksheet
$rows = []; //empty array of rows
foreach ($worksheet->getRowIterator() AS $row) {
   $cells = $row->getCellIterator();
    $cells->setIterateOnlyExistingCells(FALSE); // iterates through all cells, including empty ones
   $cellData = [];//
   foreach ($cells as $cell) {
      $cellData[] = $cell->getValue();
   }
   $rows[] = $cells; 
}

This will create 2 - dimensional array "rows" containing all the worksheet data which you can then use to import to DB. Or you can import it directly row by row in the for loop.

matri70boss
  • 349
  • 2
  • 13
  • you mean i dont have to install a bundle with composer , to use this PHPSpreadsheet package direclty what i should have to add in my controller – Imad Amzil Mar 19 '19 at 15:29
  • @ImadAmzil install PHPspreadsheet wih composer ( https://github.com/PHPOffice/PhpSpreadsheet ) , package roromix/SpreadsheetBundle is just based on PhpSpreadsheet, thats why i recomend using PHPOffice/PhpSpreadsheet and not roromix/SpreadsheetBundle – matri70boss Mar 19 '19 at 17:37