PHPWord在Laravel 5中

Xel*_*ela 7 php laravel phpword laravel-5

我想在laravel 5上使用PHPWord,但我找不到任何软件包.所以我决定手动添加它,但我仍然没有成功.

我试过这个教程和github文件:

当我昨天刚看完它时,其中一些已经消失了.

请帮忙!谢谢.

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)