PHPWord 설치

PHPWord 설치

1 설치[ | ]

[root@zetawiki ~]# cd /usr/share/php/vendor/
[root@zetawiki vendor]# git clone https://github.com/PHPOffice/PHPWord.git
Initialized empty Git repository in /usr/share/php/vendor/PHPWord/.git/
remote: Counting objects: 155485, done.
remote: Compressing objects: 100% (4926/4926), done.
remote: Total 155485 (delta 4754), reused 0 (delta 0), pack-reused 150555
Receiving objects: 100% (155485/155485), 196.69 MiB | 9.39 MiB/s, done.
Resolving deltas: 100% (148522/148522), done.
  • 짧은 경로를 사용하기 위해 심볼릭 링크 생성
[root@zetawiki vendor]# cd ..
[root@zetawiki php]# ln -s vendor/PHPWord/src/PhpWord/ PHPWord
[root@zetawiki php]# ll | grep PHPWord
lrwxrwxrwx  1 root root   27 Sep  3 12:55 PHPWord -> vendor/PHPWord/src/PhpWord/

2 hello_phpword.php 작성 및 테스트[ | ]

[root@zetawiki php]# cd
[root@zetawiki ~]# vi hello_phpword.php
<?php
require_once 'PHPWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();

$phpWord = new \PhpOffice\PhpWord\PhpWord();

$section = $phpWord->addSection();
$section->addText( htmlspecialchars(
		'"Hello" World. 안녕 친구들'
	));
$section->addText( htmlspecialchars(
		'"Lorem Ipsum 로렘 입숨'
	),
		array('name' => 'Tahoma', 'size' => 10)
	);

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('hello.docx');
[root@zetawiki ~]# php hello_phpword.php 
[root@zetawiki ~]# ll hello.docx
-rw-r--r-- 1 root root 6910 Aug 31 11:24 hello.docx
→ hello.docx를 다운로드하여 워드로 열어보니 한글도 잘 출력된다...

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}