常用
具体可参考phpoffice官方示例
vendor/phpoffice/phpspreadsheet/samples/Basic/05_Feature_demo.php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
//设置单元格值
$sheet->setCellValue('A1', $title);
//设置单元格样式,加粗,字体大小20
$spreadsheet->getActiveSheet()->getStyle('A1')->getFont()->setBold(true)->setSize(20.0);
//合并单元格
$spreadsheet->getActiveSheet()->mergeCells('A1:H1');
//设置合并后的单元格水平居中对齐
$spreadsheet->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
//报错xlsx
$writer = new Xlsx($spreadsheet);
$filename = '文件名.xlsx';
$tempnam = tempnam(sys_get_temp_dir(),'prefix');
$writer->save($tempnam);
//thinkphp5.1下载
return download($tempnam,$filename);