PHPで Excel 作成
インストールは簡単ですが。
sudo pear install OLE-1.0.0RC2
sudo pear install Spreadsheet_Excel_Writer-0.9.3
メンテが随分前に止まっているので、PHP5 では動作しません。少し弄る必要があります。
はじめに結果
- http://awm.jp/~yoya/study/php/sagami/1/excel.php
- http://awm.jp/~yoya/study/php/sagami/1/excel.phps (ソース)
以下はエラーとその修正内容。
Call-time pass-by-reference has been removed
$ php excel.php PHP Fatal error: Call-time pass-by-reference has been removed in /usr/share/php/Spreadsheet/Excel/Writer/Worksheet.php on line 2490 Fatal error: Call-time pass-by-reference has been removed in /usr/share/php/Spreadsheet/Excel/Writer/Worksheet.php on line 2490 yoya@sakurai:~/public_html/study/php/sagami/1$ p
対処
/usr/share/php/Spreadsheet/Excel/Writer$ diff Worksheet.php.0 Worksheet.php 1337c1337 < function _append($data) --- > function _append(&$data) 2490c2490 < $this->_append(&$string, true); --- > $this->_append($string, true);
…としてしまうと、
// $this->_append($header.$data); $header_and_data = $header.$data; $this->_append($header_and_data);
という風な修正が大量に発生するので、書き換える必要が出てくる。
見た感じ参照渡して変数の書き換え結果を流用する感じはしないので、単にデータコピーを回数を減らしたかったのだと仮定して、以下のだけ変更する。
2490c2490 < $this->_append(&$string, true); --- > $this->_append($string, true);
Non-static method *::* should not be called statically, assuming $this from incompatible context
$ php excel.php > excel.xls PHP Strict Standards: Non-static method OLE::Asc2Ucs() should not be called statically, assuming $this from incompatible context in /usr/share/php/Spreadsheet/Excel/Writer/Workbook.php on line 575 PHP Strict Standards: Non-static method System::tmpdir() should not be called statically, assuming $this from incompatible context in /usr/share/php/OLE/PPS/File.php on line 50 PHP Strict Standards: Non-static method System::tmpdir() should not be called statically, assuming $this from incompatible context in /usr/share/php/OLE/PPS/Root.php on line 56 PHP Strict Standards: Non-static method OLE::Asc2Ucs() should not be called statically, assuming $this from incompatible context in /usr/share/php/OLE/PPS/Root.php on line 59 PHP Strict Standards: Non-static method OLE::LocalDate2OLE() should not be called statically, assuming $this from incompatible context in /usr/share/php/OLE/PPS.php on line 190 PHP Strict Standards: Non-static method OLE::LocalDate2OLE() should not be called statically, assuming $this from incompatible context in /usr/share/php/OLE/PPS.php on line 191 PHP Strict Standards: Non-static method OLE::LocalDate2OLE() should not be called statically, assuming $this from incompatible context in /usr/share/php/OLE/PPS.php on line 190 PHP Strict Standards: Non-static method OLE::LocalDate2OLE() should not be called statically, assuming $this from incompatible context in /usr/share/php/OLE/PPS.php on line 191
対処
$ diff OLE.php.0 OLE.php 478c478 < function Asc2Ucs($ascii) --- > static function Asc2Ucs($ascii) 496c496 < function LocalDate2OLE($date = null) --- > static function LocalDate2OLE($date = null) $ diff System.php.0 System.php 462c462 < function tmpdir() --- > static function tmpdir()