使用PHP DOMDocument :: loadXML从docx文件导入数学方程和图像

问题描述 投票:0回答:1

我想将数据从docx文件导入到我的CRM,我正在使用PHP DOMDocument :: loadXML方法,但是我找不到从中导入数学公式和图像的方法。文档文件。单词文件的图像为word image

我尝试导入的代码是

    <?php
    $questionSheetRecord= readDocx("demo-stack.docx");
    echo "<pre>";
    print_r($questionSheetRecord);
    echo "</pre>";

    function readDocx($filePath) {
        // Create new ZIP archive
        $zip = new ZipArchive;
        $dataFile = 'word/document.xml';
        // Open received archive file
        $returnArray=array();
        if (true === $zip->open($filePath)) {
            // If done, search for the data file in the archive
            if (($index = $zip->locateName($dataFile)) !== false) {
                // If found, read it to the string
                $data = $zip->getFromIndex($index);
                // Close archive file
                $zip->close();
                // Load XML from a string
                // Skip errors and warnings
                $xml = DOMDocument::loadXML($data, LIBXML_NOENT | LIBXML_XINCLUDE | LIBXML_NOERROR | LIBXML_NOWARNING);
                // Return data without XML formatting tags

                foreach($xml->getElementsByTagName('p') as $child) {
                    $returnArray[]=  $child->nodeValue;
                }

                $text = $xml->saveXML();

                return $returnArray;
            }
            $zip->close();
        }
        // In case of failure return empty string
        return "";
    }
    ?>

`单词文件的链接是Word File to import data并且代码链接为Code Link

运行此代码时得到的输出是PHP Array fromat我想要这些:及其后的公式和图片。我已经回答了与该问题有关的其他问题,但它们不是该问题的适当解决方案。

谢谢

php xml dom docx
1个回答
0
投票

请浏览“ update-v1.1.php”和“ demo.docx”文件。在这里,您可以获得从Word文件中提取图像的代码,但是此代码的缺点是,如果要在Word文件中添加任何图像,则必须添加标签“ IMG1”,此处IMG具有后置值图像序列的顺序,例如如果这是单词文件中的第一个图像,则标签将为IMG1,如果它是第六个图像,则它将为IMG6。当您运行代码时,您将获得可以在任何需要的数组中使用的数组。

如果有人找到更好的解决方案,请只在这里通知我。

[我也在寻找一种将数据导出到带有图像的单词的解决方案,该图像在任何指定位置(意味着在文本句子之间,我想插入1个或多个图像)。

© www.soinside.com 2019 - 2024. All rights reserved.