一、建立一個 word檔 的基本結構:
require_once 'vendor/autoload.php'; $phpWord = new \PhpOffice\PhpWord\PhpWord(); $filename = '新文件.docx'; $filename = iconv("UTF-8", "Big5", $filename); $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); header('Content-Type: application/vnd.ms-word'); header("Content-Disposition: attachment;filename={$filename}.docx"); header('Cache-Control: max-age=0'); $objWriter->save('php://output');
更多用法請參考: