LoginSignup
15
15

More than 5 years have passed since last update.

PHPでExcelを使う(libxl)

Last updated at Posted at 2015-08-27
この記事の内容はCentOS7で実行しましたが多分他のlinuxでもつかえます。

PHPでExcelを使うにはPHPExcelを使うのが楽ですが、スピードとメモリ使用量が結構キツイです。
なので有料ですがC++で書かれたlibxlを使うと色々といい感じなので、そのインストール方法

libxlはCのライブラリなのでそのままではPHPから使えません。
素晴らしいことにこれを使用するためのextensionが公開されています
PHPExcelと紛らわしいですが・・・。

wget http://libxl.com/download/libxl-lin-3.6.2.tar.gz
tar zxf libxl-lin-3.6.2.tar.gz
cp libxl-3.6.2.0/lib64/libxl.so /usr/local/lib64/
git clone https://github.com/iliaal/php_excel.git
cd php_excel
phpize
./configure --with-libxl-incdir=../libxl-3.6.2.0/include_c/ --with-libxl-libdir=/usr/local/lib64/
make
make install

phpizeを使うにはphpの開発環境(php-develパッケージ)をインストール。
libなのかlib64なのかは環境に合わせて。

これでphp.iniに下記を追加。

extension=excel.so
excel.license_name=hogehoge
excel.license_key=linux-xxxxxxxxxxxxxxxxxxxxxxxx

ライセンスはここで書いてもいいし、excelインスタンスを作るときでもどっちでも。

xlsで日本語を使うと化ける場合は下記の様にします。

setlocale(LC_ALL, 'ja_JP.UTF-8');
$book = new ExcelBook("hogehoge", "linux-xxxxxxxxxxxxxxxxxxxxxxxx",false);
$book->setLocale('ja_JP.UTF-8');
15
15
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
15