PHP phpspreadsheet 导出大数据
1、composer 安装 phpspreadsheet 这个
composer require phpoffice/phpspreadsheet
2、composer 安装 phpspreadsheet 这个
普通的Excel根据内存来算 可能不超过4000条
普通的导出xlsx (亲测封顶3000多条)
set_time_limit(0);
for($i;$i<=60000;$i++){ // 这样6万条的话 可能
$data[] = [
'id' => $i+1,
'name' => '用户'.($i+1)
];
}
$title = [
[
'编号', '用户'
],
];
$arrData = array_merge($title, $arrData);
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
// 设置单元格格式 可以省略
$styleArray = [
'font' => [
'bold' => true,
'size' => 14,
],
];
$spreadsheet->getActiveSheet()->getStyle('A1:B1')->applyFromArray($styleArray);
$spreadsheet->getActiveSheet()->getColumnDimension('A')->setWidth(25);
$spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(25);
$spreadsheet->getActiveSheet()->fromArray($arrData);
$writer =