0

我需要使用 php 自动生成带有数学表达式的 word 文档。最好使用 Microsoft 方程、MathType 或 word 的 07+ 方程编辑器。我尝试使用 phpword 的函数 addObject() 将 MathType *.eps 文件作为 OLE 插入,但它的文件类型不支持。我应该怎么做?

    $word = new \PhpOffice\PhpWord\PhpWord();
    $section = $word->addSection();
    $section->addObject('formulas/Eqn1.eps');
    $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($word, 'Word2007');
    $objWriter->save('docs/helloWorld.docx');

错误:PhpOffice\PhpWord\Exception\InvalidObjectException

如果我尝试添加为数学:

$section->addText('
    <w:p w:rsidR="00D14CAF" w:rsidRDefault="00A07C15">
        <m:oMathPara>
            <m:oMath>
                <m:r>
                    <w:rPr>
                        <w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math"/>
                    </w:rPr>
                    <m:t>XXXXXXXXXXXXXX</m:t>
                </m:r>
            </m:oMath>
        </m:oMathPara>
        <w:bookmarkStart w:id="0" w:name="_GoBack"/>
        <w:bookmarkEnd w:id="0"/>
    </w:p>
        ');

*.docx 无法打开(错误)

4

2 回答 2

0

The file does not open cause there's xml tag elements in the text. I needed to insert equations into a document and the easiest way was to render the equation using mathjax then save an image with html2canvas and insert with phpWord addImage(). I hope this helps.

于 2016-11-24T16:53:25.273 回答
0

为新开发人员添加答案。

php-docx 库可以在这里提供帮助,这是一个示例

https://www.phpdocx.com/api-documentation/word-content/add-math-OMML-Word-document-with-PHP

于 2021-01-06T14:31:00.040 回答