嗨,我有一个关于php word的问题。当我在文件中使用重音字符时,文件已损坏,无法打开。
<?php
require_once 'PHPWord.php';
$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate('Documents/LM.docx');
$document->setValue('Value1', "example with accent évian");
$document->save('Documents/LMD.docx');
?>发布于 2017-01-27 20:22:49
我假设您的代码生成的word文件在没有特殊重音字符的情况下不会损坏。但不管怎样,你能试试下面的版本吗?0.13.0版本中不推荐使用loadTemplate函数,应使用TemplateProcessor代替,文本内容通常应使用+ htmlspecialchars换行。
$templateProcessor = new PhpWord\TemplateProcessor('Documents/LM.docx');
$templateProcessor->setValue('Value1', htmlspecialchars('example with accent évian', ENT_COMPAT, 'UTF-8'));
$templateProcessor->saveAs('Documents/LMD.docx');这对我来说在PhpWord 0.13.0上没有问题。
https://stackoverflow.com/questions/41802091
复制相似问题