PHPExcel类导出
<?php
$title = array('title1', 'title2'); // excel表头
$list = array( // 要导出的列表数据
array('test1', 'test11'),
array('test2', 'test22'),
array('test3', 'test33'),
);
array_unshift($list, $title);
require './lib/PHPExcel.php';
$objPHPExcel = new PHPExcel();
/*以下就是对处理Excel里的数据, 横着取数据,主要是这一步,其他基本都不要改*/
foreach ($list as $k => $v) {
$num = $k + 1;
$objPHPExcel->setActiveSheetIndex(0)//Excel的第A列,$v[0]是你查出数组的键值,下面以此类推
->setCellValue('A' . $num, $v[0])
->setCellValue('B' . $num, $v[1]);
}
//生成xls文件
$objPHPExcel->getActiveSheet()->setTitle('list');
$objPHPExcel->setActiveSheetIndex(0);
$filename = 'workload';
ob_end_clean(); // 防止乱码,清空ob缓存
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $filename . '.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
结果如下
不用PHPExcel类的导出请点击:https://my.oschina.net/lianglc/blog/3079667