安装composer require phpoffice/phpspreadsheetuse PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Border;$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();//从65开,65是第1列,66是第二列,2是第二行
$sheet->setCellValue(strtoupper(chr(65)) . '1', '大得');
$sheet->setCellValue(strtoupper(chr(66)) . '1', '大得');
$sheet->setCellValue(strtoupper(chr(66)) . '2', '大2');header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename=/www/wwwroot/swoole/erp-test-zhoao2/excel/666.xlsx"');
header('Cache-Control: max-age=0');
$writer = new Xlsx($spreadsheet);
$date = date("Ymd");
$Absolute_Path=$_SERVER['SCRIPT_FILENAME'];
$user_path = substr($Absolute_Path,0,-9)."storage/cdjdade/{$date}";//保存路径
if(!is_dir($user_path)){mkdir($user_path);
}
$writer->save($user_path.'/666.xlsx');
//删除清空:
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);