我正在使用 PHPSpreadsheet 创建和 excel 文件当我填充我的数据时它不会传递列 'Z' 当对于此查询我的数据实际上有 81 列时。
下面是我的代码:
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getDefaultColumnDimension()->setWidth(19);
$sheet->getStyle('A:ZZ')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT);
$sheet->getStyle('A:ZZ')->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER);
// $sheet->getStyle('A:U')->getAlignment()->setWrapText(true);
$sheet->getStyle('A1:ZZ1')->applyFromArray($headerStyleArray);
$sheet->getStyle('A:ZZ')->applyFromArray($fontArray);
// SET EXCEL HEADER &COLUMN WIDTH TO AUTOSIZE
$i=0;
foreach (range('A', $spreadsheet->getActiveSheet()->getHighestDataColumn()) as $col) {
$spreadsheet->getActiveSheet()
->getColumnDimension($col)
->setAutoSize(true);
$sheet->getCell($col.'1')->setValue($header[$i]);
if($i >= count($header)-1) {
break;
}
$i++;
}
// SET EXCEL CELL DATA
$rowNumber = 2;
foreach($rows as $row) {
$i = 0;
foreach (range('A', $spreadsheet->getActiveSheet()->getHighestDataColumn()) as $char) {
return response()->json($char.$rowNumber);
if($i <= count($row)-1) {
$sheet->getCell($char.$rowNumber)->setValue($row[$i]);
}
$i++;
}
$rowNumber++;
}
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'. $request->group_name. ' Member Attendance Report.xlsx"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
return;
开心每一天1111