【问题标题】:PHPWord - Class ''PhpOffice\PhpWord\PhpWord' not foundPHPWord - 找不到类“PhpOffice\PhpWord\PhpWord”
【发布时间】:2020-05-18 09:08:03
【问题描述】:

遇到错误 找不到类“PhpOffice\PhpWord\PhpWord” 我的 composer.json "php": ">=7.0.0", "abrigham/laravel-email-exceptions": "^1.3", "barryvdh/laravel-debugbar": "^3.2", “barryvdh/laravel-dompdf”:“^0.8.4”, "ckfinder/ckfinder-laravel-package": "^3.5", "karlomikus/主题": "^1.0", “laravel/框架”:“5.5.”, “laravel/社交名媛”:“^3.0”, "laravel/tinker": "~1.0", "laravelcollective/html": "^5.4.0", "leafo/scssphp": "^0.7.7", "maatwebsite/excel": "~2.1.0", "nicolaslopezj/searchable": "1.", "niklasravnsborg/laravel-pdf": "^3.1", "phpoffice/phpword": "^0.17.0", "shivella/laravel-bitly": "^1.0", "simplesoftwareio/simple-qrcode": "^2.0", "sofa/laravel-global-scope": "^0.2.0", "yajra/laravel-datatables": "^1.0", "yajra/laravel-datatables-oracle": "^8.0", "zendframework/zend-escaper": "^2.6", "zendframework/zend-stdlib": "^3.2"

【问题讨论】:

  • 执行这个命令composer dump-autoload
  • 请格式化您的代码。另请说明您正在开发的框架和其他详细信息。
  • 请分享更多细节。您是否检查过该类是否正确存储?您是否检查过自动加载器是否包含在内?

标签: php laravel


【解决方案1】:

也许这个answer可以帮助你

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


  [1]: https://stackoverflow.com/a/31627457/1873569

【讨论】:

  • 请为您的答案添加一些进一步的解释。所有这些代码,尤其是爱因斯坦的那句话,如何解决问题中给出的自动加载器问题?
猜你喜欢
  • 2019-08-30
  • 2017-03-08
  • 2019-03-20
  • 2018-02-08
  • 2018-04-28
  • 1970-01-01
  • 2020-01-31
  • 2018-05-27
  • 2014-07-19
相关资源
最近更新 更多