要在PHP項目中引入PHPWord,首先需要確保已經安裝了Composer,并且已經在項目中初始化了Composer。
{
"require": {
"phpoffice/phpword": "^0.17.0"
}
}
composer install
require_once 'vendor/autoload.php';
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('Hello World!');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
通過上述步驟,就可以在PHP項目中成功引入PHPWord,并開始使用它來生成Word文檔。