寫在前面:php
PHPExcel is a library written in pure PHP and providing a set of classes that allow you to write to and read from different spreadsheet file formats, like Excel (BIFF) .xls, Excel 2007 (OfficeOpenXML) .xlsx, CSV, Libre/OpenOffice Calc .ods, Gnumeric, PDF, HTML, ... This project is built around Microsoft's OpenXML standard and PHP.bash
這是個十分強大的插件,有不少功能,下面是它所支持的. Readingui
Writingspa
相關要求插件
<?php
/**
* Created by Zoe.
* User: Administrator
* Date: 2017/2/8
* Time: 9:16
*/
$dir = dirname(__FILE__);//find the path of current script
require_once '../Classes/PHPExcel.php';//use the file
$objPHPExcel = new PHPExcel();//實例化=>new excel in desk
$objSheet = $objPHPExcel->getActiveSheet();//得到當前活動sheet的操做對象
$objSheet->getTitle("demo");//set name
//$objSheet->setCellValue("A1","姓名")->setCellValue("B1","分數");//fill data
//$objSheet->setCellValue("A2","小啦虎")->setCellValue("B2","88");//fill data
$array = array(
array("","name","score"),
array("","Zoe","100"),
array("","John","99")
);
$objSheet->fromArray($array);//直接加載數據塊來填充數據
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,"Excel2007");//按照指定格式生成excel文件
$objWriter ->save($dir."/demo_1.xlsx");//save file
複製代碼
推薦使用setCellValue. ##MYSQL配置文件##excel