HTML to docx Converter 설치

HTML to docx Converter 설치

1 사전 작업[ | ]

2 다운로드[ | ]

3 설치[ | ]

[root@zetawiki ~]# cd /usr/share/php/
[root@zetawiki php]# ll htmltodocx*
-rw-r--r-- 1 root root 623496 Sep  9 13:06 htmltodocx_0_6_5_alpha.zip
  • 하위폴더 htmltodocx에 압축해제
[root@zetawiki php]# 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
  • 확인 후 zip 파일 삭제
[root@zetawiki php]# ll | grep htmltodocx
drwxr-xr-x  7 root root   4096 Sep  9 13:08 htmltodocx
-rw-r--r--  1 root root 623496 Sep  9 13:06 htmltodocx_0_6_5_alpha.zip
[root@zetawiki php]# rm -f htmltodocx_0_6_5_alpha.zip
[root@zetawiki php]#

4 test1.php 작성[ | ]

  • 홈 폴더로 이동하여 test1.php 작성
[root@zetawiki php]# cd
[root@zetawiki ~]# vi test1.php
<?php
require_once 'htmltodocx/phpword/PHPWord.php';
require_once 'htmltodocx/simplehtmldom/simple_html_dom.php';
require_once '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 테스트[ | ]

[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 참고[ | ]

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