dsgnze6572 2014-09-30 01:51
浏览 219

PHPWord创建模板 - 替换封面.docx上的文本

Okay so I'm using PHPWord creating a template. Then using the function setValue to replace the different strings in the document this all works correctly but I have a cover page on my document and the text is not replaced on this page?

Is there a way to add this functionality, In essence all that needs to happen is the replace (setValue) needs to run on the xml that corresponds to the cover page (title, and assets)(custom xml folder?). you can see these by extracting the .docx file after changing the file extension to .zip

https://github.com/PHPOffice/PHPWord/blob/master/src/PhpWord/Template.php

How I'm currently creating the .docx from the templated .docx file:

<?php
include_once 'Sample_Header.php';

// New Word document
echo date('H:i:s') , " Create new PhpWord object" , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();

$document = $phpWord->loadTemplate('resources/Template_Proposal.docx');

$document->setValue('CONTACTNAME', 'John');
$document->setValue('BUSINESSNAME', 'JBS Marketing');
$document->setValue('WEBSITE', 'www.website.com.au');
$document->setValue('DATE', '07/07/2014');

$name = 'test-proposal.docx';
echo date('H:i:s'), " Write to Word2007 format", EOL;
$document->saveAs($name);
rename($name, "results/{$name}");

echo getEndingNotes(array('Word2007' => 'docx'));
if (!CLI) {
    include_once 'Sample_Footer.php';
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?