【问题标题】:How to read/rewrite .doc file as xml in nodeJS?如何在nodeJS中将.doc文件读取/重写为xml?
【发布时间】:2019-07-26 07:35:12
【问题描述】:

我需要阅读 .doc 文件,更改一些属性并保存它。我该怎么做?

我可以读取 .docx 文件,如下所示:

const zip = new AdmZip(filePath);
const xml = zip.readAsText('word/document.xml');
console.log(xml)

//<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
//<w:document //xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessi//ngCanvas" //xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" //xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chart//ex...

我尝试像这样阅读 .doc:

const expectedXml = fs.readFileSync(filePath);

但我得到了不分青红皂白的结果。

我希望得到 .docx 示例中的 xml。

【问题讨论】:

    标签: node.js xml parsing docx doc


    【解决方案1】:

    Microsoft DOC 文件早于 DOCX 并且不基于压缩 (OPC) XML (OOXML);他们是binary file format

    一次性在 MS Word 或 LibreOffice 中打开 DOC 文件,然后重新另存为 DOCX。

    要在 NodeJS 中以编程方式提取文本,请使用 textract 等包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多