* 현재 html 문서를 doc파일로 다운로드
https://stackoverflow.com/questions/40628171/how-to-convert-html-to-word-using-php
<? header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=Report.doc"); // 주의! docx 확장자는 에러
?>
//---------------------------
* docx 문서 파일 생성
https://github.com/PHPOffice/PHPWord
composer require phpoffice/phpword
$pw = new \PhpOffice\PhpWord\PhpWord();
$section = $pw->addSection();
$section->addText('텍스트' );
$html = "<h1>제목</h1>";
$html .= "<p>문단</p>";
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
$pw->save( "워드.docx", "Word2007");
//----------------------
// 참고
Convert or Export HTML text to MS Word with PHP Script
https://www.webslesson.info/2016/08/convert-or-export-html-text-to-ms-word-with-php-script.html
How to Export HTML to Word Document with JavaScript
https://phppot.com/javascript/how-to-export-html-to-word-document-with-javascript/
How to Convert HTML to DOCX Using PHP
https://code-boxx.com/convert-html-to-docx-using-php/
'Code > PHP' 카테고리의 다른 글
[php] Extension 리스트 정리 (0) | 2020.03.09 |
---|---|
[PHP] Enchant , 스펠링 체크 모듈 사용법 (0) | 2020.03.09 |
[php] composer 경고 메시지 처리 - moontoast/math is abandoned (0) | 2020.03.04 |
[php] Xdebug 사용법, php 브레이크 포인트 걸기 (0) | 2019.10.31 |
[php] array_walk , array_map 사용법 (0) | 2019.09.05 |