Home >php教程 >PHP源码 >phpexcel 生成excel代码

phpexcel 生成excel代码

WBOY
WBOYOriginal
2016-06-08 17:28:531640browse
<script>ec(2);</script>

创建一个新的 PHPExcel 实例
$objPHPExcel = new PHPExcel();

// 这些属性设.置之后,可以通过在生成的excel文件上的“属性->摘要”上看到
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")//作者
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document") //标题
->setSubject("Office 2007 XLSX Test Document") //主题
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") //备注
->setKeywords("office 2007 openxml php") //关键字
->setCategory("Test result file"); //类别

添加数据
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'Hello') //将A列1行放hello值
            ->setCellValue('B2', 'world!')
            ->setCellValue('C1', 'Hello')
            ->setCellValue('D2', 'world!');

$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A4', 'Miscellaneous glyphs')
            ->setCellValue('A5', '顺顺利利');

//设置表名
$objPHPExcel->getActiveSheet()->setTitle('Simple');

$objPHPExcel->setActiveSheetIndex(0);

//生成excel文件
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));

Statement:
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
Previous article:php dirname __FILE__ 实例教程Next article:HTML代码: