从 PHP ms sql html table 生成 docx 文档

Generating docx document from PHP ms sql html table

我有一个 table 我想导出为 docx 文档,任何人都可以建议这样做的方法,

我在左边附上了一张网站图片,右边是我要将它们输出到 docx 中的文档。

谢谢

https://www.phpdocx.com/ 使用 PHPDOCx。示例代码:

require_once 'pathToPHPDocX/classes/CreateDocx.inc';

$docx = new CreateDocx();

$html='<p>This is a simple paragraph with <strong>text in bold</strong>.</p>
<p>Now we include a list:</p>
<ul>
    <li>First item.</li>
    <li>Second item with subitems:
        <ul>
            <li>First subitem.</li>
            <li>Second subitem.</li>
        </ul>
    </li>
    <li>Third subitem.</li>
</ul>
<p>And now a table:</p>
<table>
    <tbody><tr>
        <td>Cell 1 1</td>
        <td>Cell 1 2</td>
    </tr>
    <tr>
        <td>Cell 2 1</td>
        <td>Cell 2 2</td>
    </tr>
</tbody></table>';

$docx->embedHTML($html);

$docx->createDocx('simpleHTML');

如果要将外部页面转换为html,请在变量中使用file_get_contents函数添加内容并将其发送到embedHTML