vendredi 13 décembre 2019

How to export lines db table to csv file with phpspreadsheet

In laravel 5.7 with "phpoffice/phpspreadsheet": "^1.6" app I need to export lines db table to csv file, like :

$dataLines= [ 
    ['field1'=>'000000000', 'field2'=>1111111111111],
    ['field1'=>'11000000000', 'field2'=>221111111111111],
    ['field1'=>'31000000000', 'field2'=>321111111111111],
];


$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Csv($spreadsheet);

$writer->save('/path/12345.csv');

But with code above I have empty file and I did find not way to write content of $dataLines array. Also as I need to write 1 row as fields name and next rows from db, have I to prepare 1st row with fields name and rest rows (only values without fields name) manually ? Are there some mothods to make it automatically ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire