"PHPWord 설치"의 두 판 사이의 차이

(새 문서: ;PHPWord 설치 ==설치== <source lang='cli'> [root@zetawiki ~]# cd /usr/share/php/vendor/ [root@zetawiki vendor]# git clone https://github.com/PHPOffice/PHPWord.git Initialized emp...)
 
잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(사용자 3명의 중간 판 13개는 보이지 않습니다)
2번째 줄: 2번째 줄:


==설치==
==설치==
<source lang='cli'>
*[[/usr/share/php/vendor/]] 폴더로 이동하여 git clone으로 설치
<syntaxhighlight lang='console'>
[root@zetawiki ~]# cd /usr/share/php/vendor/
[root@zetawiki ~]# cd /usr/share/php/vendor/
[root@zetawiki vendor]# git clone https://github.com/PHPOffice/PHPWord.git
[root@zetawiki vendor]# git clone https://github.com/PHPOffice/PHPWord.git
11번째 줄: 12번째 줄:
Receiving objects: 100% (155485/155485), 196.69 MiB | 9.39 MiB/s, done.
Receiving objects: 100% (155485/155485), 196.69 MiB | 9.39 MiB/s, done.
Resolving deltas: 100% (148522/148522), done.
Resolving deltas: 100% (148522/148522), done.
</source>
</syntaxhighlight>
*짧은 경로를 사용하기 위해 심볼릭 링크 생성
<syntaxhighlight lang='console'>
[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/
</syntaxhighlight>
 
==hello_phpword.php 작성 및 테스트==
<syntaxhighlight lang='console'>
[root@zetawiki php]# cd
[root@zetawiki ~]# vi hello_phpword.php
</syntaxhighlight>
<syntaxhighlight lang='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');
</syntaxhighlight>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# php hello_phpword.php
[root@zetawiki ~]# ll hello.docx
-rw-r--r-- 1 root root 6910 Aug 31 11:24 hello.docx
</syntaxhighlight>
:→ hello.docx를 다운로드하여 워드로 열어보니 한글도 잘 출력된다...


==같이 보기==
==같이 보기==
*[[PHPExcel 설치]]
*[[PHPExcel 설치]]
*[[HTML to docx Converter 설치]]
*[[PHPWord 서버에 저장하지 않고 다운로드시키기]]
==참고==
*https://github.com/PHPOffice/PHPWord


[[분류: PHPWord]]
[[분류: PHPWord]]

2020년 11월 2일 (월) 02:56 기준 최신판

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 }}