Reputation: 806
I have a working code in controller as shown below, problem is that when I wanted to edit its content, it doesn't save.
Controller
$rows = Excel::load($file_path, function($reader) use ($column_number)
{
$reader->takeColumns($column_number);
$reader->noHeading();
})->get();
$rows = $rows->toArray();
View Content
dump($rows[0][0]); // this will display A1 cell and it is working fine
But when I try to do like this
$rows[0][0] = "Test"; // this will not write the cell A1
dump($rows); // but it will display as shown in picture below
Upvotes: 1
Views: 1136
Reputation: 1300
Load your file by sheet index and append your values
$download_file_name = 'DataFile';
Excel::selectSheetsByIndex(1)->load($file_path, function($reader) use () {
$reader->sheet('Sheet1', function($sheet) use () {
//if you want to add value append single value
$sheet->SetCellValue("A7", "Exporter");
//if want to append row
$sheet->appendRow($dispColArray);
});
}, 'UTF-8')->setFilename($download_file_name)->download('xls');
You can also use for the following function for sheet style
For sheet style
$sheet->setStyle(array(
'font' => array(
'name' => 'Calibri',
'size' => 9,
'background' => '#ffffff'
)
));
Merge cell and design
$sheet->mergeCells('A1:D4');
$sheet->cells('A1:D4', function($cells) {
$cells->setBackground('#ffffff');
});
Upvotes: 1
Reputation: 142
You can modify the values inside the Excel Load.
$rows = Excel::load($file_path, function($reader)
{
$reader->sheet('sheet1', function($sheet){
$sheet->cells('E4', function($cell) {
$cell->setValue('my value');
});
});
})->store('xls');
Upvotes: 0