【问题标题】:adding to SetValue Methode Php Variable In PhpWord在 PhpWord 中添加到 SetValue Methode Php 变量
【发布时间】:2019-11-01 21:43:55
【问题描述】:

我正在使用 PhpWord 将页面转换为 docx 文件

在我的主页中,我有一个表单

$(document).on('submit', '#save', function () {
        event.preventDefault();
        var textareaValue = $('#content').summernote('code');

        $.ajax({
            type: 'POST',
            url: 'convert_doc.php',
            data: ({text:textareaValue}),
            success: (
                function (data) {
                    $(".result").html(data)
                }

            )
        });

    });
<form method="post" novalidate="novalidate" id="save" >
  <textarea class="summernote input-block-level" id="content" name="content" rows="18"></textarea>                                                               <buttontype="submit" >save file</button>
 </form>
                                        
                                       

在我的 convert_doc.php 文件中我有这个代码:

if(isset($_POST['text'])){


require '../vendor/autoload.php';
    $desc1 = $_POST['text'];

    $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('tamplate.docx');

    $templateProcessor->setValue('summer', 'Word Document processing');

    $templateProcessor->saveAs('export.docx');

}

当我试图将 Word 文档处理替换为

$templateProcessor->setValue('summer', $desc1);

我保存的文件已损坏。 我知道第二个值必须是纯文本。我怎样才能把 PHP 变量而不是文本?

【问题讨论】:

    标签: php docx phpword


    【解决方案1】:

    很可能您的$_POST['text'] 包含由 JS 发布的无效数据(就 MS Word 而言)。首先调试并尝试修复它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-03
      • 2012-10-23
      • 2021-11-01
      • 2021-03-29
      相关资源
      最近更新 更多