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 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭