"HTML to docx Converter 스타일 적용하기"의 두 판 사이의 차이

(새 문서: ;HTML to docx Converter 스타일 적용하기 ==사전 작업== 분류:HTML to docx Converter)
 
잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(사용자 2명의 중간 판 5개는 보이지 않습니다)
2번째 줄: 2번째 줄:


==사전 작업==
==사전 작업==
*[[HTML to docx Converter 서버에 저장하지 않고 다운로드시키기]]


==htmltodocx3.php 작성==
<syntaxhighlight lang='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');
</syntaxhighlight>
==테스트==
*http://zetawiki.com/ex/htmltodocx/htmltodocx3.php
==같이 보기==
*[[HTML to docx Converter 서버에 저장하지 않고 다운로드시키기]]
*[[HTML to docx Converter 그림파일 포함 + 서버에 저장하지 않고 다운로드시키기]]
==참고==
*https://phpword.readthedocs.org/en/latest/styles.html


[[분류:HTML to docx Converter]]
[[분류:HTML to docx Converter]]

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

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