PHPでExcelファイルを操作するPHPExcel。
インストールしてみたので、メモメモ
■前提
・Apache上にPHPが動いているものとします。
ちなみに、今使っているのはPHP Version 5.3.18
ダウンロードしてきたinstall.txtには、こんな風に書いてあります。
* PHP version 5.2.0 or higher
* PHP extension php_zip enabled *)
* PHP extension php_xml enabled
* PHP extension php_gd2 enabled (if not compiled in)
■ダウンロード
PHPExcel
http://phpexcel.codeplex.com/
のサイトに行って、Downloadをくりっく。
そうしたら、スクロールしてみてください。
今回は、
PHPExcel 1.7.8 - with Documentation in MS Office format
をクリックして、ダウンロードしてきました。
■インストール
(1)まず、ダウンロードしたZIPファイルを解凍します
(2)apacheのhtdocs(公開ファイルを置くところ)に
(フォルダの中に)
ClassesとTestsをコピーしてください。
(Testsはサンプル用なので、コピーしなくてもよいが、
以下、コピーしたものとして、話を進める)
■Hello出力
今回は、Testsの下の、01pharSimple.phpを動かすことにします。
(1)インストールの(2)でコピーしたTestsフォルダ内にある
01pharSimple.phpをエディタで開いてください
(2)以下の行(37行目かな?)
require_once '../Build/PHPExcel.phar';
|
を
require_once '../Classes/PHPExcel.php';
|
と修正してください(つまり、コピーしたClasses/PHPExcel.phpを
インクルードで参照するようにしてください)
(3)ブラウザから、
http://localhost/Tests/01pharSimple.php
をみると、
04:32:21 Create new PHPExcel object
04:32:22 Set document properties
04:32:22 Add some data
04:32:22 Rename worksheet
04:32:22 Write to Excel2007 format
04:32:22 File written to 01pharSimple.xlsx
04:32:22 Write to Excel5 format
04:32:22 File written to 01pharSimple.xls
04:32:22 Peak memory usage: 7.25 MB
04:32:22 Done writing files
Files have been created in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Tests
|
と表示されるので
(4)Testsフォルダをみると、
Excelファイル 01pharSimple.xls ができていて、
それを開くと、Hello World!とか書いてあるはず。