2018-08-01 · 百度认证:云南新华电脑职业培训学校官方账号
云南新华电脑学校
云南新华电脑学校是经云南省教育厅批准成立的省(部)级重点计算机专业学校,采用三元化管理模式,教学设备先进,师资雄厚学生毕业即就业,学院引进了电商企业入驻,创建心为电商创业园区,实现在校即创业
向TA提问
关注
展开全部
下载phpexcel类库 代码如下:
<?php
require_once('PHPExcel.php');
require_once('PHPExcel/IOFactory.php');
$objPHPExcel=new PHPExcel();
$iofactory=new IOFactory();
//获得数据 ---一般是从数据库中获得数据
$data=array(
0=>array('id'=>2013,'name'=>'张某某','age'=>21),
1=>array('id'=>201,'name'=>'EVA','age'=>21)
);
//设置excel列名
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1','编号');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B1','姓名');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C1','年龄');
//把数据循环写入excel中
foreach($data as $key => $value){
$key+=2;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$key,$value['id']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$key,$value['name']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C'.$key,$value['age']);
}
//excel保存在根目录下 如要导出文件,以下改为注释代码
$objPHPExcel->getActiveSheet() -> setTitle('SetExcelName');
$objPHPExcel-> setActiveSheetIndex(0);
$objWriter = $iofactory -> createWriter($objPHPExcel, 'Excel2007');
$objWriter -> save('SetExcelName.xlsx');
//导出代码
// $objPHPExcel->getActiveSheet() -> setTitle('SetExcelName');
// $objPHPExcel-> setActiveSheetIndex(0);
// $objWriter = $iofactory -> createWriter($objPHPExcel, 'Excel2007');
// $filename = 'SetExcelName.xlsx';
// header('Content-Type: application/vnd.ms-excel');
// header('Content-Type: application/octet-stream');
// header('Content-Disposition: attachment; filename="' . $filename . '"');
// header('Cache-Control: max-age=0');
// $objWriter -> save('php://output');
?>
<?php
require_once('PHPExcel.php');
require_once('PHPExcel/IOFactory.php');
$objPHPExcel=new PHPExcel();
$iofactory=new IOFactory();
//获得数据 ---一般是从数据库中获得数据
$data=array(
0=>array('id'=>2013,'name'=>'张某某','age'=>21),
1=>array('id'=>201,'name'=>'EVA','age'=>21)
);
//设置excel列名
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1','编号');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B1','姓名');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C1','年龄');
//把数据循环写入excel中
foreach($data as $key => $value){
$key+=2;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$key,$value['id']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$key,$value['name']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C'.$key,$value['age']);
}
//excel保存在根目录下 如要导出文件,以下改为注释代码
$objPHPExcel->getActiveSheet() -> setTitle('SetExcelName');
$objPHPExcel-> setActiveSheetIndex(0);
$objWriter = $iofactory -> createWriter($objPHPExcel, 'Excel2007');
$objWriter -> save('SetExcelName.xlsx');
//导出代码
// $objPHPExcel->getActiveSheet() -> setTitle('SetExcelName');
// $objPHPExcel-> setActiveSheetIndex(0);
// $objWriter = $iofactory -> createWriter($objPHPExcel, 'Excel2007');
// $filename = 'SetExcelName.xlsx';
// header('Content-Type: application/vnd.ms-excel');
// header('Content-Type: application/octet-stream');
// header('Content-Disposition: attachment; filename="' . $filename . '"');
// header('Cache-Control: max-age=0');
// $objWriter -> save('php://output');
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询