[root@zetawiki ~]# cd /usr/share/php/vendor/
[root@zetawiki vendor]# ll htmltodocx_0_6_5_alpha.zip
-rw-r--r-- 1 root root 623496 Aug 31 13:03 htmltodocx_0_6_5_alpha.zip
- HTML to docx Converter 설치
1 사전 작업
2 다운로드
- https://htmltodocx.codeplex.com/ 접속
- [download] 클릭하여 htmltodocx_0_6_5_alpha.zip 다운로드(609KB)
3 설치
- 서버의 /usr/share/php/vendor 폴더에 zip파일 업로드[1]
Copy
- 하위폴더 만들고 압축해제
Copy
[root@zetawiki vendor]# mkdir htmltodocx
[root@zetawiki vendor]# unzip htmltodocx_0_6_5_alpha.zip -dhtmltodocx
... (생략)
inflating: htmltodocx/simplehtmldom/manual/manual_faq.htm
inflating: htmltodocx/simplehtmldom/simple_html_dom.php
inflating: htmltodocx/example.php
- 경로단축을 위해 심볼릭링크 생성
Copy
[root@zetawiki vendor]# cd ..
[root@zetawiki php]# ln -s vendor/htmltodocx/ htmltodocx
[root@zetawiki php]# ll | grep htmltodocx
lrwxrwxrwx 1 root root 18 Sep 9 11:21 htmltodocx -> vendor/htmltodocx/
4 test1.php 작성
Copy
[root@zetawiki ~]# vi test1.php
PHP
Copy
<?php
require_once 'vendor/htmltodocx/phpword/PHPWord.php';
require_once 'vendor/htmltodocx/simplehtmldom/simple_html_dom.php';
require_once 'vendor/htmltodocx/htmltodocx_converter/h2d_htmlconverter.php';
$html = '<html>
<body>
<h1>Hello 친구들</h1>
<ul>
<li>하나</li>
<li>둘</li>
</ul>
<table>
<tr><td>1</td><td>한놈</td></tr>
<tr><td>2</td><td>두시기</td></tr>
<tr><td>3</td><td>석삼</td></tr>
</table>
</body>
</html>';
$html_dom = new simple_html_dom();
$html_dom->load($html);
$html_arr = $html_dom->find('html',0)->children();
$phpword = new PHPWord();
$section = $phpword->createSection();
$state = array(
'phpword_object' => &$phpword,
);
htmltodocx_insert_html($section, $html_arr[0]->nodes, $state);
$objWriter = PHPWord_IOFactory::createWriter($phpword, 'Word2007');
$objWriter->save('sample1.docx');
5 테스트
Copy
[root@zetawiki ~]# php test1.php
[root@zetawiki ~]# ll sample1.docx
-rw-r--r-- 1 root root 8526 Sep 1 15:01 sample1.docx
- → sample1.docx를 받아보니 잘 된다...
6 같이 보기
7 참고 자료
- ↑ 폴더가 없으면 만들어서 넣자.
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.