保存的文档中的表格和文本

时间:2018-12-11 06:48:48

标签: php docx phpword

我有代码

$html = "<p>text text text</p><table><tr><td>test</td><td>test</td></tr></table><p>text text text</p>";

    require_once '/vendor/phpword/vendor/autoload.php';
    $pw = new \PhpOffice\PhpWord\PhpWord();
    $section = $pw->addSection();
    \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
    $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($pw, 'Word2007');
    $objWriter->save('name.docx');

    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment;filename=name.docx');
    $objWriter->save('php://output');

在保存的文档中,我没有表格,只有文字。表格标签会删除并以文本形式插入。该如何解决?我的文字本身包含一个表格,因此无法单独添加。

0 个答案:

没有答案