HTML to docx Converter 설치

Jmnote (토론 | 기여)님의 2015년 9월 1일 (화) 15:03 판 (→‎test1.php 작성)
HTML to docx Converter 설치

1 다운로드

2 설치

Copy
[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
  • 하위폴더 만들고 압축해제
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

3 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');

4 테스트

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를 받아보니 잘 된다...

5 같이 보기

6 참고 자료

  1. 폴더가 없으면 만들어서 넣자.