如何使用phpspreadsheet
库从数组创建 excel 工作表列标题?
下面是我正在尝试的代码,但它不起作用:
// $header is an array containing column headers
$header = array("Customer Number", "Customer Name", "Address", "City", "State", "Zip");
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->fromArray($header, NULL, 'A1');
// redirect output to client browser
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="myfile.xlsx"');
header('Cache-Control: max-age=0');
$writer = new Xlsx($spreadsheet);
$writer->save('php://output');