[英]How do I read the header or footer of a Word document with docx4js?
I can read the contents of the file with 我可以用它读取文件的内容
docx4js.load(fileName)).then(docx => {
console.log("Content of the body is: " + docx.officeDocument.content.text());
});
But how do I print out the text in the header? 但是如何打印标题中的文本?
In docx, there is only 1 header and 1 footer. 在docx中,只有1个页眉和1个页脚。 You cant have a footer in 1st page that is unlike footer in 2nd page and same goes with header.
你不能在第一页有一个页脚,不像第二页的页脚,同样与标题相同。 Once you change the header in any of the pages, all headers on other pages change.
更改任何页面中的标题后,其他页面上的所有标题都会更改。 So getting the 1st header or footer is like getting them for all pages.
所以获得第一个页眉或页脚就像是为所有页面获取它们。
To get header you do it like 为了获得标题,你可以这样做
docx.getObjectPart("word/header1.xml").text();
And you can do the same thing for the footer 你可以为页脚做同样的事情
docx.getObjectPart("word/footer1.xml").text();
you can get the content/body as well doing like 你也可以得到内容/身体
docx.getObjectPart("word/document.xml").text();
这似乎从第一页得到了标题文本,至少:
docx.getObjectPart("word/header1.xml").text()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.