我在控制器中有一个工作代码,如下所示,问题是当我要编辑其内容时,它无法保存。
控制器
$rows = Excel::load($file_path, function($reader) use ($column_number)
{
$reader->takeColumns($column_number);
$reader->noHeading();
})->get();
$rows = $rows->toArray();
查看内容
dump($rows[0][0]); // this will display A1 cell and it is working fine
但是当我尝试这样做
$rows[0][0] = "Test"; // this will not write the cell A1
dump($rows); // but it will display as shown in picture below
答案 0 :(得分:1)
通过工作表索引加载文件并附加值
$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');
您还可以将以下功能用于图纸样式
用于工作表样式
$sheet->setStyle(array(
'font' => array(
'name' => 'Calibri',
'size' => 9,
'background' => '#ffffff'
)
));
合并单元格和设计
$sheet->mergeCells('A1:D4');
$sheet->cells('A1:D4', function($cells) {
$cells->setBackground('#ffffff');
});
答案 1 :(得分:0)
您可以在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');