PHPExcel导出数据的基本使用方法

 1 <?php
 2 //引入excel文件
 3 include "Phpexcel/Phpexcel.php";
 4 include "Phpexcel/Phpexcel/Writer/Excel2007.php";
 5 //实例化对象
 6 $objExcel = new PHPExcel();
 7 //获得当前sheet操作对象
 8 $objSheet = $objExcel->getActiveSheet();
 9 //设置sheet名称
10 $objSheet->setTitle('mysheet');
11 //填充数据 一
12 /*$objSheet->setCellValue('A1','ID')
13    ->setCellValue('B1','班级')
14    ->setCellValue('C1','姓名')
15    ->setCellValue('D1','性别')
16    ->setCellValue('E1','分数');
17 $objSheet->setCellValue('A2','1')
18    ->setCellValue('B2','一班')
19    ->setCellValue('C2','james')
20    ->setCellValue('D2','男')
21    ->setCellValue('E2','60');
22 $objSheet->setCellValue('A3','2')
23    ->setCellValue('B3','二班')
24    ->setCellValue('C3','Mares')
25    ->setCellValue('D3','女')
26    ->setCellValue('E3','70');
27 $objSheet->setCellValue('A4','3')
28    ->setCellValue('B4','三班')
29    ->setCellValue('C4','mariros')
30    ->setCellValue('D4','男')
31    ->setCellValue('E4','80');*/
32 //填充数据 数组形式
33 $excelArr = array(
34    array('ID','班级','姓名','性别','分数'),
35    array('1','一班','高飞','男','60'),
36    array('2','二班','乔丹','男','50'),
37    array('3','三班','布莱尔','女','40'),
38    array('4','四班','大卫','男','30'),
39 );
40 $objSheet->fromArray($excelArr);
41 //写入数据
42 $objWriter = PHPExcel_IOFactory::createWriter($objExcel,'Excel2007');
43 //保存数据
44 $objWriter->save('myexcel2.xlsx');
45       
46       
47       
48       
49       
50       

 

你可能感兴趣的:(PHPExcel导出数据的基本使用方法)