<!-- 使用PHPExcel导出文件代码实现,PHPExcel探索之旅教程-慕课网 -->
<!-- 视频教程地址:https://www.imooc.com/video/8364 -->
<?php
$dir=dirname(__FILE__); //找到当前脚本所在目录
require $dir."/PHPExcel/PHPExcel.php"; //加载文件
$objPHPExcel=new PHPExcel(); // 实例化PHPEXcel类,等同于在桌面上新建一个excel表格
$objSheet=$objPHPExcel->getActiveSheet(); // 获得当前活动sheet的操作对象
$objSheet->setTitle("demo");// 给当前活动Sheet设置名称,即工作表名
$objSheet->setCellValue("A1","姓名")->setCellValue("B1","分数");// 给当前活动Sheet填充数据
$objSheet->setCellValue("A2","张三")->setCellValue("B2","68");
$objSheet->setCellValue("A3","李四")->setCellValue("B3","80");
$objSheet->setCellValue("A4","王五")->setCellValue("B4","78");
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,"Excel2007");// 按照指定格式生成excel文件。
$objWriter->save($dir."/demo.xlsx");
?>
2018-11-14
$dir=dirname(__FILE__);
$objPHPExcel= new PHPExcel();
$objSheet=$objPHPExcel->getActiveSheet();
$objSheet->setTitle('demo');
$objSheet->setCellValue('A1','姓名')->setCellValue('B1','分数');
$objSheet->setCellValue('A2','张三')->setCellValue('B2','100');
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$objWriter->save($dir.'demo.xlsx');
2018-11-14
$dir=dirname(__FILE__);
$objPHPExcel= new PHPExcel();
$objSheet=$objPHPExcel->getActiveSheet();
$objSheet->setTitle('demo');
$objSheet->setCellValue('A1','姓名')->setCellValue('B1','分数');
$objSheet->setCellValue('A2','张三')->setCellValue('B2','100');
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$objWriter->save($dir.'demo.xlsx');
笔记:导出步骤
$dir=dirname(__FILE__);
$objPHPExcel= new PHPExcel();
$objSheet=$objPHPExcel->getActiveSheet();
$objSheet->setTitle('demo');
$objSheet->setCellValue('A1','姓名')->setCellValue('B1','分数');
$objSheet->setCellValue('A2','张三')->setCellValue('B2','100');
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$objWriter->save($dir.'demo.xlsx');
老师的逻辑好强大
1,引入数据库
2,引入PHPExcel
3,实例化数据库 并传入数据库配置参数
4,实例化PHPExcel类
$objPHPExcel = new PHPExcel();//等同于在桌面新建一个excel
5,新建内置表 根据数据库数据可以建几个内置表
6,创建新内置表
$objPHPExcel->createSheet();
7,把新创建的sheet设定为当前sheet 再循环里用
$objPHPExcel->setActiveSheetIndex($i-1);
8,获取当前活动sheet
$objSheet = $objPHPExcel->getActiveSheet();
9,查询数据库数据存入表中
设置每个sheet的名字
$objSheet->setTitle('excel_'.$i);
设置A1行
$objSheet->setCellValue('A1','姓名')->setCellValue('B1','分数');
10,填充数据
11,生成excel文件 保存
$objWrite=PHPExcel_IOFactory::createWrite($objPHPExcel,'Excel5');
$objWrite->save($dir.'/export_1.xls');
mark !!!
PHPExcel导入文件,读取Excel数据
Excel 导出步骤
PHPExcel导入文件功能~
PHPExcel导出数据库数据Demo2
PHPExcel代码现实现Demo
PHPExcel实现导出功能的步骤