dtjw6660 2015-07-25 06:18
浏览 103
已采纳

在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.

I have tried this tutorials and github files:

Also some of it was gone when I just read it yesterday.

Please help! Thanks.

  • 写回答

1条回答 默认 最新

  • douyan1927 2015-07-25 06:26
    关注

    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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部