Spreadsheet_Excel_Writer 설치하기
============================== PHP 버전이 4점대인 경우 =========================================
root로 로그인 한 후
[root@SERVER root]#
/usr/local/php/bin 디렉토리로 이동
[root@SERVER root]# cd /usr/local/php/bin
pear 설치 목록 확인
[root@SERVER bin]# ./pear list
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.2 stable
Console_Getopt 1.2.1 stable
HTML_Template_IT 1.1 stable
Net_UserAgent_Detect 2.0.1 stable
PEAR 1.5.0 stable
Structures_Graph 1.0.2 stable
OLE 설치
[root@SERVER bin]# ./pear install ole-beta
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update
downloading OLE-1.0.0RC1.tgz ...
Starting to download OLE-1.0.0RC1.tgz (12,153 bytes)
.....done: 12,153 bytes
install ok: channel://pear.php.net/OLE-1.0.0RC1
Spreadsheet_Excel_Writer 설치
[root@SERVER bin]# ./pear install Spreadsheet_Excel_Writer-beta
WARNING: channel "pear.php.net" has updated its protocols, use "channel-update pear.php.net" to update
downloading Spreadsheet_Excel_Writer-0.9.2.tgz ...
Starting to download Spreadsheet_Excel_Writer-0.9.2.tgz (57,629 bytes)
..............done: 57,629 bytes
install ok: channel://pear.php.net/Spreadsheet_Excel_Writer-0.9.2
============================== PHP 버전이 5점대인 경우 ==================
* PHP php-5.2.10 에서 pear, pecl이 정상동작을 안한다.
실제로 실행해 보자.
[root@SERVER bin]# pear install ole-beta
pear.php.net is using a unsupported protocal - This should never happen.
install failed
위와 같은 에러가 발생한다.
** 해결방법 **
.channels 디렉토리를 백업해 두고 다시 설치한 후 인스톨 한다.
1. .channels 백업
[root@SERVER php]# mv .channels .channels-broken
2. .channels 업데이트
[root@SERVER php]# pear update-channels
Updating channel "doc.php.net"
Update of Channel "doc.php.net" succeeded
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
3. 설치 하고자 하는게 있는지 확인 후
[root@SERVER php]# pear list
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.3 stable
Console_Getopt 1.2.3 stable
PEAR 1.8.0 stable
Structures_Graph 1.0.2 stable
XML_Util 1.2.1 stable
4. 설치 (OLE)
[root@SERVER]# pear install ole-beta
downloading OLE-1.0.0RC1.tgz ...
Starting to download OLE-1.0.0RC1.tgz (12,153 bytes)
.....done: 12,153 bytes
install ok: channel://pear.php.net/OLE-1.0.0RC1
5. 설치(Spreadsheet_Excel_Writer)
[root@SERVER php]# pear install Spreadsheet_Excel_Writer-beta
downloading Spreadsheet_Excel_Writer-0.9.2.tgz ...
Starting to download Spreadsheet_Excel_Writer-0.9.2.tgz (57,629 bytes)
..............done: 57,629 bytes
install ok: channel://pear.php.net/Spreadsheet_Excel_Writer-0.9.2
6. 설치 확인
[root@SERVER php]# pear list
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.3 stable
Console_Getopt 1.2.3 stable
OLE 1.0.0RC1 beta
PEAR 1.8.0 stable
Spreadsheet_Excel_Writer 0.9.2 beta
Structures_Graph 1.0.2 stable
XML_Util 1.2.1 stable
======================= php적용 예제 =============================================================
<?php
require_once 'Spreadsheet/Excel/Writer.php';
$file_name = date("ymdHi").".xls";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Description: PHP4 Generated Data");
$workbook = new Spreadsheet_Excel_Writer();
// sending HTTP headers
$workbook->send($file_name);
$workbook->setVersion (8); // 버전(Excel 97/2000)
// Creating a worksheet
$worksheet =& $workbook->addWorksheet('sheet1');
$worksheet->setInputEncoding('EUC-KR'); // 한글 인코딩
$worksheet->write(0, 0,"제목1");
$worksheet->write(0, 1,"제목2");
$worksheet->write(0, 2,"제목3");
$worksheet->write(1, 0,"내용1");
$worksheet->write(1, 1,"내용2");
$worksheet->write(1, 2,"내용3");
$workbook->close();
?>