PHPWord in Laravel 5 [closed]

空扰寡人 提交于 2019-12-03 13:04:08

问题


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.

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.

Please help! Thanks.


回答1:


PHPWord is on Packagist, so installing it on Laravel is as easy as:

composer require phpoffice/phpword

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');


来源:https://stackoverflow.com/questions/31627389/phpword-in-laravel-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!