PHPExcel(更新中)

仇諾伊發表於2017-12-13

寫在前面:

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.

這是個十分強大的外掛,有很多功能,下面是它所支援的. Reading

  • BIFF 5-8 (.xls) Excel 95 and above
  • Office Open XML (.xlsx) Excel 2007 and above
  • SpreadsheetML (.xml) Excel 2003
  • Open Document Format/OASIS (.ods)
  • Gnumeric
  • HTML
  • SYLK
  • CSV

Writing

  • BIFF 8 (.xls) Excel 95 and above
  • Office Open XML (.xlsx) Excel 2007 and above
  • HTML
  • CSV
  • PDF (using either the tcPDF, DomPDF or mPDF libraries, which need to be installed separately)

相關要求

  • PHP version 5.2.0 or higher
  • PHP extension php_zip enabled (required if you need PHPExcel to handle .xlsx .ods or .gnumeric files)
  • PHP extension php_xml enabled
  • PHP extension php_gd2 enabled (optional, but required for exact column width autocalculation) 使用PHPexcel匯出檔案
    匯出excel步驟
    簡單例子
<?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配置檔案##

相關文章