Append Rows to existing Excel document using Laravel-Excel
Solution 1
Right now it is not possible to edit an Excel file like I intended to. Source: package creator.
Solution 2
Laravel Excel 1.2.0 added support for appending rows (so modifying existing Excel files)
http://www.maatwebsite.nl/laravel-excel/docs/import#edit
The correct code would be:
Excel::load($path . '/exported.xls', function($reader)
{
$reader->sheet(function($sheet)
{
// Manipulate third row
$sheet->row(3, array(
'test1', 'test2'
));
});
})->export('xls');
Solution 3
It looks like you would use...
$sheet->appendRow(array(
'appended', 'appended'
));
Found in the docs here... http://www.maatwebsite.nl/laravel-excel/docs/export
Glad To Help
Updated on June 04, 2022Comments
-
Glad To Help almost 2 years
I have an existing Excel document, to which I want to append some data using Laravel-Excel. The package has nice documentation but unfortunately there is no full example showing how to do that, but only partial demonstration of manipulating rows.
What I am attempting to do is:
- open the existing document
- get the first sheet, append new
- close the document
The code:
Excel::load($path . '/exported.xls', function($reader){ $sheet = $reader->getActiveSheet(); // Manipulate third row $sheet->row(3, array( 'test1', 'test2' )); });
Which results in
Call to undefined method PHPExcel_Worksheet::row()
Has anyone succeeded appending data with this package?