1.类扩展包位置:
2.引用
/**
*
* 导出Excel
*/
public function excel()
{
//引入PHPExcel库文件
Vendor('phpexcel2.PHPExcel');
//创建对象
$excel = new \PHPExcel();
//Excel表格式,这里简略写了8列
$letter = array('A', 'B', 'C', 'D', 'E', 'F', 'F', 'G','H','I','J','k','L','M','N','O','P','Q','R','S');
//表头数组
$tableheader = array('序号', '资产编号', '设备名称', '主机名', '设备型号', '密级', '用途','密级编号', '所属部门', '放置地点', '责任人', '硬盘序列号', 'ip地址', 'MAC地址','操作系统', '安装时间', '启用时间', '使用情况', '是否需要制作保密标签','创建时间');
//填充表头信息
for ($i = 0; $i < count($tableheader); $i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1", "$tableheader[$i]");
}
//表格数组
$data = array(
array('1', 'B', 'C', 'D', 'E', 'F', 'G'),
array('2', 'B', 'C', 'D', 'E', 'F', 'G'),
array('3', 'B', 'C', 'D', 'E', 'F', 'G'),
array('4', 'B', 'C', 'D', 'E', 'F', 'G'),
array('5', 'B', 'C', 'D', 'E', 'F', 'G'),
array('6', 'B', 'C', 'D', 'E', 'F', 'G'),
array('7', 'B', 'C', 'D', 'E', 'F', 'G'),
);
$tz = M('taizhang');
$data2 = $tz->field('type',true)->select();
//print_r($data2);exit();
//填充表格信息
for ($i = 2; $i <= count($data2) + 1; $i++) {
$j = 0;
foreach ($data2[$i - 2] as $key => $value) {
$excel->getActiveSheet()->setCellValue("$letter[$j]$i", "$value");
$j++;
}
}
//创建Excel输入对象
$write = new \PHPExcel_Writer_Excel5($excel);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="信息系统表.xlsx"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
}