CodeIgniter PHPWord using as third_party

孤街浪徒 提交于 2019-12-04 12:35:30

From Russia with love;) Use like this in library for CodeIgniter:

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


    require_once  APPPATH.'/libraries/PHPWord/src/PhpWord/Autoloader.php';
    use PhpOffice\PhpWord\Autoloader as Autoloader;
    Autoloader::register();

    class Word extends Autoloader {

    }

    ?>

In controller like code from samples:

$this->load->library('word');
/* remove ;)
#require_once 'PHPWord/src/PhpWord/Autoloader.php';
#PhpOffice\PhpWord\Autoloader::register();
*/

// Template processor instance creation
echo date('H:i:s') , ' Creating new TemplateProcessor instance...' ;
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('text.docx');


$templateProcessor->setValue('sss','123');

echo date('H:i:s'), ' Saving the result document...';
$templateProcessor->saveAs('test1.docx');

Tested it works!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!