HTML to docx Converter 스타일 적용하기

HTML to docx Converter 스타일 적용하기

1 사전 작업[ | ]

2 htmltodocx3.php 작성[ | ]

<?php
require_once 'htmltodocx/phpword/PHPWord.php';
require_once 'htmltodocx/simplehtmldom/simple_html_dom.php';
require_once 'htmltodocx/htmltodocx_converter/h2d_htmlconverter.php';

$styles = array();
$styles['default'] = array( 'size' => 11 );
$styles['elements'] = array(
	'h1' => array( 'bold' => true, 'size' => 20 ),
	'h2' => array( 'bold' => true, 'size' => 15 ),
	'h3' => array( 'bold' => true, 'size' => 12 ),
	'table' => array(
		'borderColor' => '000000',
		'borderSize' => 10,
	),
	'th' => array(
		'bgColor' => 'abcdef',
		'bold' => true,
	),
);
$styles['classes'] = array(
	'red-text' => array( 'color' => 'ff0000' ),
);

$html = '<html>
<body>
	<h1>Hello 친구들</h1>
	<ul class="red-text">
		<li>하나</li>
		<li>둘</li>
	</ul>
	<table>
		<tr><th>번호</th><th>이름</th></tr>
		<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,
	'style_sheet' => $styles,
);
htmltodocx_insert_html($section, $html_arr[0]->nodes, $state);

$writer = PHPWord_IOFactory::createWriter($phpWord, 'Word2007');

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="htmltodocx3.docx"');
header('Cache-Control: max-age=0');

3 테스트[ | ]

4 같이 보기[ | ]

5 참고[ | ]

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