* 현재 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/

 

반응형
Posted by codens