如何在 nodeJS 中将 read/rewrite .doc 文件作为 xml?

How to read/rewrite .doc file as xml in nodeJS?

我需要读取 .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);

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

我希望得到 xml 就像在 .docx 的例子中那样。

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

一次性使用 MS Word 或 LibreOffice 打开 DOC 文件并重新保存为 DOCX。

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

等包