Laravel 5 中的 PHPWord
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31627389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHPWord in Laravel 5
提问by Xela
I want to use PHPWord on laravel 5 but I cannot find any packages for it. So I decided to add it manually but still I do not have success.
我想在 laravel 5 上使用 PHPWord,但找不到任何软件包。所以我决定手动添加它,但我仍然没有成功。
I have tried this tutorials and github files:
我已经尝试过本教程和 github 文件:
Also some of it was gone when I just read it yesterday.
昨天刚读的时候,其中一些已经消失了。
Please help! Thanks.
请帮忙!谢谢。
回答by Ben Claar
PHPWord is on Packagist, so installing it on Laravel is as easy as:
PHPWord 在Packagist 上,所以在 Laravel 上安装它就像:
composer require phpoffice/phpword
or adding this to your composer.json then running composer install
:
或将此添加到您的 composer.json 然后运行composer install
:
"require": {
"phpoffice/phpword": "dev-master"
}
Once installed, you can use it in your code like this (taken from the documentation):
安装后,您可以像这样在代码中使用它(取自文档):
// 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');