前言
在学习一个php案例
一、使用步骤
1.引入库
代码如下(示例):
<?php require "D:/phpstudy_pro/WWW/PHPExcel/PHPExcel.php";//引入PHPExcel对象 $localFileName = 'downloaded_excel.xlsx'; $objPHPExcel=new PHPExcel();//创建对象 $objSheet=$objPHPExcel->getActiveSheet();//拿到对象的操作方法来做事 $objSheet->setTitle("demo");//excel标题 $objSheet->setCellValue("A1","姓名")->setCellValue("B1","分数"); //A1 写姓名 B2写分数,看下面的图片哈 $objSheet->setCellValue("A2","张三")->setCellValue("B2","50"); /*$array=array( array("姓名","分数"), array("李四","60"), array("王五","70") );*/ //或者生成数组也行 $objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,"Excel2007"); //生成excel2007版本号 $objWriter->save("D:/demo.slsx"); $objWriter->save($localFileName); // 下载Excel文件 header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $localFileName . '"'); header('Content-Length: ' . filesize($localFileName)); readfile($localFileName);
2.效果
总结
写完了,谢谢大家