Laravel 5 中的 PHPWord

PHPWord in Laravel 5

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

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

还有昨天刚看的时候有一部分不见了

请帮忙!谢谢

PHPWord 在 Packagist 上,因此在 Laravel 上安装它非常简单:

composer require phpoffice/phpword

或将此添加到您的 composer.json 然后 运行 composer install:

"require": {
   "phpoffice/phpword": "dev-master"
}

安装后,您可以像这样在代码中使用它(取自 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');