Spreadsheet创建多个表
2022-06-02 PHP 1395
$times = [ [ 'name' => '2022-01', 'time' => ['2022-01-01', '2022-02-01'], ], [ 'name' => '2022-02', 'time' => ['2022-02-01', '2022-03-01'], ], [ 'name' => '2022-03', 'time' => ['2022-03-01', '2022-04-01'], ], [ 'name' => '2022-04', 'time' => ['2022-04-01', '2022-05-01'], ], [ 'name' => '2022-05', 'time' => ['2022-05-01', '2022-06-01'], ], ]; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->setTitle($times[0]['name']); foreach ($times as $key => $value) { if ($key > 0) { $worksheet = new Worksheet($spreadsheet, $value['name']); $spreadsheet->addSheet($worksheet); } } $filename = '测试订单.xlsx'; header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="' . $filename . '"'); header('Cache-Control: max-age=0'); $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('php://output'); //$writer->save('hello2.xlsx');
很赞哦! (0)
相关文章
文章评论
-
-
-
0条评论