在利用
其實在眾多方法中感覺Pear中的Spreadsheet_Excel_Writer很是好用。關於PHP Spreadsheet_Excel_Writer的安裝本文不予介紹。
以下為PHP Spreadsheet_Excel_Writer的引用的內容:
- < ?php
- //調用Writer.php
- require_once ‘Spreadsheet/Excel/Writer.php’;
- //創建Workbook
- $workbook = new Spreadsheet_Excel_Writer();
- //定義導出Excel文件名
- $workbook->send(’test.xls’);
- //創建Worksheet
- $worksheet =& $workbook->addWorksheet(’My first worksheet’);
- //設置字體大小
- $format_column = & $workbook->addformat(array(’Size’=>9,’Bold’=>1));
- //數據寫入
- //標題行(第一行)
- $worksheet->write(0, 0, ‘Name’, $format_column);
- $worksheet->write(0, 1, ‘Age’, $format_column);
- //第一個人(第二行)
- $worksheet->write(1, 0, ‘John Smith’);
- $worksheet->write(1, 1, 30);
- //第二個人(第三行)
- $worksheet->write(2, 0, ‘Johann Schmidt’);
- $worksheet->write(2, 1, 31);
- //第三個人(第四行)
- $worksheet->write(3, 0, ‘Juan Herrera’);
- $worksheet->write(3, 1, 32);
- //關閉Workbook
- $workbook->close();
- ?>
以上代碼示例就是PHP Spreadsheet_Excel_Writer的具體使用方法。