phpExcel之导出数据(php+mysql)
发表于2017-08-28 11:38 | 次阅读 | 0条评论 | 作者:siru90
文件结构如图:
说明:
PHPExcel.php和PHPExcel文件,是引入文件
phpexcel_output.php:
<?php
require_once "PHPExcel.php";
$objExcel = new PHPExcel();
//设置参数
//设值
$objExcel->getActiveSheet()->setCellValue('A1', '季度');
$objExcel->getActiveSheet()->setCellValue('B1', '名称');
$objExcel->getActiveSheet()->setCellValue('C1', '数量');
$i = 2;
$data = array(
array("quarter"=>"春季", "name"=>"呵呵", "number"=>"33"),
array("quarter"=>"夏季", "name"=>"哈哈", "number"=>"33")
);
foreach($data as $item){
$objExcel->getActiveSheet()->setCellValue('A'.$i, $item['quarter']);
$objExcel->getActiveSheet()->setCellValue('B'.$i, $item['name']);
$objExcel->getActiveSheet()->setCellValue('C'.$i, $item['number']);
$i++;
}
//设置导出文件名
$outputFileName = 'total.xls';
$xlsWriter = new PHPExcel_Writer_Excel5($objExcel);
//ob_start(); ob_flush();
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="'.$outputFileName.'"');
header("Content-Transfer-Encoding: binary");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
$xlsWriter->save( "php://output" );
?>