Ben*_*aar 16
PHPWord在Packagist上,因此在Laravel上安装它就像下面这样简单:
composer require phpoffice/phpword
Run Code Online (Sandbox Code Playgroud)
或者将它添加到您的composer.json然后运行composer install:
"require": {
"phpoffice/phpword": "dev-master"
}
Run Code Online (Sandbox Code Playgroud)
安装完成后,您可以在代码中使用它(取自文档):
// Creating the new document...
$phpWord = new \PhpOffice\PhpWord\PhpWord();
/* Note: any element you append to a document must reside inside of a Section. */
// Adding an empty Section to the document...
$section = $phpWord->addSection();
// Adding Text element to the Section having font styled by default...
$section->addText(
htmlspecialchars(
'"Learn from yesterday, live for today, hope for tomorrow. '
. 'The important thing is not to stop questioning." '
. '(Albert Einstein)'
)
);
// Saving the document as HTML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
$objWriter->save('helloWorld.html');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16243 次 |
| 最近记录: |