时间:2021-07-01 10:21:17 帮助过:4人阅读
$excel=new \PHPExcel();
do{
$url='http://www.哪个好人来答下.com';
$content='';
$content=file_get_contents($url);
if($content['status']==0){
$data=$content['results'];
$head=array();
//获取表头值
for($i=0;$i<10;$i++){
$tmp=array_keys($data[$i]);
foreach($tmp as $t){
if(!in_array($t,$head)){
array_push($head,$t);
}
}
}
$A=65; //A的ASCII值
$col=array();
for($i=0;$iarray_push($col,chr($A++));
}
for($i=0;$i$excel->getActiveSheet()->setCellValue($col[$i].'1',$head[$i]);
}
}
foreach($data as $key=>$val){
for($i=0;$i
$excel->getActiveSheet()->setCellValue($col[$i].$i,$row[$head[$i]]);
}
}
}
$page++;
}while($pageCount>=$page);
$excel->getActiveSheet()->setTitle($title);
$excel->setActiveSheetIndex(0);
$writer = \PHPExcel_IOFactory::createWriter($excel, 'Excel5');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$fileName.'.xls"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
}
ob_end_clean();// 就是加这句
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$fileName.'.xls"');
header('Cache-Control: max-age=0');