0

他们已经根据以下内容更新了插件并替换了一些共享类:https ://github.com/PHPOffice/PHPWord/releases 并且在升级 phpword 时,我遇到了这个错误。

A PHP Error was encountered

Severity: Error

Message: Class 'PhpOffice\Common\Text' not found

Filename: Element/Text.php

Line Number: 139





<?php
include_once(APPPATH."third_party/PHPWord/Autoloader.php");
if (!defined('BASEPATH'))
    exit('No direct script access allowed');


use PhpOffice\PhpWord\Autoloader;
use PhpOffice\PhpWord\Settings;
Autoloader::register();
Settings::loadConfig();


class Test extends CI_Controller {

    public function index() {
                $phpWord = new \PhpOffice\PhpWord\PhpWord();
                $phpWord->getCompatibility()->setOoxmlVersion(14);
                $phpWord->getCompatibility()->setOoxmlVersion(15);

                $section = $phpWord->addSection();
                $html = '<p><strong style="font-weight: 600;"This is a heading</strong></p>

                $filename = 'test.doc';

                \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
                $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
                $objWriter->save($filename);
                header('Content-Description: File Transfer');
                header('Content-Type: application/octet-stream');
                header('Content-Disposition: attachment; filename='.$filename);
                header('Content-Transfer-Encoding: binary');
                header('Expires: 0');
                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                header('Pragma: public');
                header('Content-Length: ' . filesize($filename));
                flush();
                readfile($filename);
                unlink($filename); // deletes the temporary file
                exit;
        }
}

我使用过composer,我想知道如何使用公共共享库:https ://github.com/PHPOffice/Common

请帮忙。

4

1 回答 1

0

你可以用终端SSH你的服务器来使用composer并避免第三方目录吗?我只是尝试用 Composer 安装 PHPWord。成功地。公共目录默认在 PHPWord 包中。但我有这个问题。它可以通过这种方式解决,或者甚至更好。我使用了PHPWord GitHub页面中的基本代码示例。

最好在修复该行之前将 PHPWord 分叉到您自己的存储库中,然后调用您的存储库以避免将来在更新包的情况下中断。我不确定他们为什么不解决这个问题。

按照这 4 个步骤来重现我自己对 composer 的使用。

然后,您的示例类应如下所示:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

use PhpOffice\PhpWord\PhpWord;

class Welcome extends CI_Controller
{

    public function index()
    {
        try {
            // code example from GitHub https://github.com/PHPOffice/PHPWord#getting-started
            // without require 'bootstrap.php' line, following 4 steps you already auto-loaded classes
    } catch (\Exception $e) {
          echo $e->getMessage();
    }
}

你应该得到helloWorld.docx,helloWorld.odthelloWorld.html文件的FCPATH位置。

于 2017-08-30T17:47:17.340 回答