1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7 に LibXL をインストールする

Posted at

CentOS7にLibXLをインストールしてPHP5.4からExcelを出力する

LibXLをダウンロードする

ここからでも入手できます
http://www.libxl.com/

# cd /usr/local/src
# wget http://libxl.com/download/libxl-lin-3.6.4.tar.gz
# tar -zxvf libxl-lin-3.6.4.tar.gz

php_excelをインストールする

libxml2がインストールされていない場合はyumでインストールする
yum install libxml2-devel

# wget https://github.com/iliaal/php_excel/archive/master.zip
# unzip master.zip
# cd php_excel-master
# phpize
# ./configure --with-libxl-incdir=../libxl-3.6.4.0/include_c --with-libxl-libdir=../libxl-3.6.4.0/lib64 --with-libxml-dir=/usr/include/libxml2
# make
# make install

インストールされたモジュールをPHPに組み込む

/etc/php.d/excel.ini
extension=excel.so
;excel.license_name=LICENSE_NAME
;excel.license_key=LICENSE_KEY

Apacheを再起動して有効になっているかを確認する

# systemctl restart httpd
# php -i | grep excel
excel support => enabled

PHPからExcelを出力する

<?php

$excel = new ExcelBook(null, null, true);

$sheet = $excel->addSheet('sheet1');
for ($row = 0; $row < 100; $row++) {
    for ($col = 0; $col < 100; $col++) {
        $sheet->write($row, $col, time());
    }
}

header('Content-Type: application/octet-stream');
header('Content-Disposition:attachment;filename="sample.xlsx"');
$excel->save('php://output');
1
2
1

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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?