"require-dev": { "phpoffice/phpspreadsheet": "^1.6" },
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\IOFactory;
$spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->setTitle('工做表格1'); $spreadsheet->getActiveSheet()->setTitle('Hello'); //表頭 $k = 1; $worksheet->setCellValue('A'.$k, '業務類型'); $worksheet->setCellValue('B'.$k, '商品總價'); $worksheet->setCellValue('C'.$k, '被推薦費'); $worksheet->setCellValue('D'.$k, '推薦費'); $worksheet->setCellValue('E'.$k, '成本費'); $worksheet->setCellValue('F'.$k, '商家應得'); //設置單元格內容 if($order){ $k = 2; //從第二行開始 foreach ($order as $key =>$val) { $worksheet->setCellValue('A'.$k, $val['pl_alias']); $worksheet->setCellValue('B'.$k, $val['price_total']); $worksheet->setCellValue('C'.$k, $val['be_recNum']); $worksheet->setCellValue('D'.$k, $val['be_recNum']); $worksheet->setCellValue('E'.$k, $val['recNum']); $worksheet->setCellValue('F'.$k, $val['deserved']); $k++; } } $fileName = '每日收益--'.$get['start_time'].'.xlsx'; header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="'.$fileName.'"'); header('Cache-Control: max-age=0'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('php://output');