laravel读取excel

时间:2022-08-02 18:27:08
$filePath = 'storage/exports/成员信息.xls';
Excel::load($filePath, function ($reader) {
// $data = $reader->all();//获取全部
// $data = $reader->get()->first();//获取第一条记录
// $data = $reader->takeRows(2)->get();//获取指定几条记录
            $data = $reader->skipRows(3)->get()->toArray();//跳过几行
// $head = $reader->get()->getHeading();//获取头部
      
->limitRows();#读取行数

echo '<pre>';
print_r($data);
// print_r($head);
});
参考地址:https://docs.laravel-excel.com/2.1/import/results.html
Excel::create($fileName, function ($excel) use ($excelData, $highLightArray) {
$excel->sheet('sheet1', function ($sheet) use ($excelData, $highLightArray) { $sheet->fromArray($excelData, null, 'A1', false, false);
$lineKey = [1 => 'A', 2 => 'B', 3 => 'C'];
foreach ($highLightArray AS $key => $value) {
$index = $lineKey[$value] . $key;
$sheet->cells($index, function ($cells) {
$cells->setFontColor('#0000FF');
});
}
}); })->store('xls');
////下载到项目目录中