sam*_*xli 3 xml docx ms-office openxml office-interop
当您打开Word时,它允许您另存为Word Open XML格式。我看到过有关以zip格式打开docx文件,然后从中提取内容的帖子。但是我真正想要的是一种将docx转换为单个XML的方法,就像在MS Office中执行“另存为”操作时一样。该怎么办?
以及如何针对.doc格式执行此操作?
注意:我想以编程方式执行此操作。最好在Linux开发条件下使用PHP。但是,如果那不可用,那么其他语言也可以。最后,如果要解决这个问题,我可以考虑旋转Windows服务器来执行此操作。
很抱歉恢复死线程,但我刚刚找到了DOCX文件的答案。DOCX文件只是XML文件的ZIP存档。因此,要提取其文件v.gr的内容。在Linux环境下的word / document.xml,您必须运行解压缩:
unzip -q -c myfile.docx word/document.xml
Run Code Online (Sandbox Code Playgroud)
要将此命令的输出捕获到PHP脚本的$ xml变量中,可以发出:
$xml = shell_exec ("unzip -q -c myfile.docx word/document.xml");
Run Code Online (Sandbox Code Playgroud)
希望此答案有助于DOCX文件。迟到总比不到好。
对于DOC文件,此方法无效。
在Word中:文件| 另存为 | Word XML 文档 (*.xml) 为您提供所需的 Open XML 格式,作为单个 XML 文件
在使用Interop的代码中:使用Document对象的SaveAs方法,使用WdSaveFormat.wdFormatXMLDocument作为保存格式。您还应该使用 Document.Convert 方法来更新与已安装的 MS Office 版本的兼容性。
因此,不一定是完整的演示,但这应该给您正确的想法:
ActiveDocument.Convert();
WdSaveFormat myNewSaveFormat = WdSaveFormat.wdFormatXMLDocument;
ActiveDocument.SaveAs(newFilePath, myNewSaveFormat); //where newFilePath can be a FileInfo object specifying the new file name and extension (docx)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
47376 次 |
| 最近记录: |