PHPWord在Laravel 5中 [英] PHPWord in Laravel 5
本文介绍了PHPWord在Laravel 5中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在laravel 5上使用PHPWord,但找不到任何软件包.因此,我决定手动添加它,但仍然没有成功.
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.
我已经尝试过本教程和github文件:
I have tried this tutorials and github files:
- https://github.com/maveius/Laravel-Word
- http://laravel.io/forum/05-26-2014-how-can-i-export-to-word
昨天我刚刚读到它时,其中的一些也消失了.
Also some of it was gone when I just read it yesterday.
请帮助!谢谢.
推荐答案
PHPWord位于 Packagist 上,因此将其安装在Laravel就像:
PHPWord is on Packagist, so installing it on Laravel is as easy as:
composer require phpoffice/phpword
或将其添加到您的composer.json中,然后运行composer install
:
or adding this to your composer.json then running 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');
这篇关于PHPWord在Laravel 5中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文