PHP 中使用jupitern/docx将多个work文档合并为一个word文档

jupitern/docx

PHP Docx tolls.

docx模板系统
将docx文件合并到一个文件中
可选择在合并文件之间添加分页符

版本要求

PHP 5.4 or higher.

安装插件

composer require jupitern/docx

Include jupitern/docx in your project, by adding it to your composer.json file.


{
    "require": {
        "jupitern/docx": "1.*"
    }
}

样例

$dir = 'C:\\www\\docx\\';

// 模板替换操作
$docx = \Jupitern\Docx\Docx::instance()
			->setTemplate($dir.'template.docx')
			->setData(['{name}' => 'john doe', '{address}' => 'at the end of the road'])
			->save($dir.'result.docx');

// 合并文件
$docxMerge = \Jupitern\Docx\DocxMerge::instance()
    // 添加要合并的文件数组
	->addFiles([$dir.'file1.docx', $dir.'file2.docx'])
    // 输出文件路径和分页符参数
	->save($dir.'result.docx', true);

github https://github.com/jupitern/docx?tab=readme-ov-file