Export files using PHPExcel_PHP tutorial

WBOY
Release: 2016-07-13 09:44:48
Original
896 people have browsed it

Export file using PHPExcel

Export steps

1. Create a new excel table

Instantiate the PHPExcel class

2. Create sheet (built-in table)

createSheet()

setActiveSheetIndex()

getActiveSheet()

3. Fill in data

setCellValue()

4. Save the file

PHPExcel_IOFactory::createWriter()

save()

<!--?php
$dir = dirname(__FILE__);
//Include class
require_once($dir.&#39;/PHPExcel.php&#39;);


$objPHPExcel = new PHPExcel(); //实例化PHPExcel类
$objPHPExcel--->setActiveSheetIndex(0);
$objSheet = $objPHPExcel->getActiveSheet(); //获得当前sheet
$objSheet->setTitle(demo); //给当前sheet设置名称

$array = array(
	array(姓名,分数),
	array(李四,60),
	array(王五,70)
);

$objSheet->setCellValue(A5,姓名);
$objSheet->setCellValue(B5,分数); //给当前sheet填充数据
$objSheet->setCellValue(A6,张三);
$objSheet->setCellValue(B6,70);

$objSheet->fromArray($array); //直接加载数据块填充数据
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, &#39;Excel2007&#39;); //按照指定格式生成excel文件

$objWriter->save(str_replace(&#39;.php&#39;, &#39;.xls&#39;, __FILE__));
Copy after login


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1047176.htmlTechArticleUse PHPExcel to export files Export steps 1. Create a new excel table and instantiate the PHPExcel class 2. Create a sheet (built-in table) createSheet() setActiveSheetIndex() getActiveSheet() 3. Fill in the data...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template