要在PHP項(xiàng)目中引入PHPWord,首先需要確保已經(jīng)安裝了Composer,并且已經(jīng)在項(xiàng)目中初始化了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項(xiàng)目中成功引入PHPWord,并開始使用它來生成Word文檔。