简体   繁体   English

如何使用docx4js读取Word文档的页眉或页脚?

[英]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.

相关问题 如何使用 JavaScript 在浏览器中呈现 Word 文档(.doc、.docx)? - How do I render a Word document (.doc, .docx) in the browser using JavaScript? 如何使用angular在HTML中呈现Word文档(.doc,.docx) - How do I render a Word document (.doc, .docx) in the HTML using angular 使用Docx.js在JavaScript中生成Word文档? - Generate a Word document in JavaScript with Docx.js? 如何获取HTML文档以引用其他HTML文档中的“页眉”和“页脚”元素? - How do I get a HTML document to refer to the “header” and “footer” elements in other HTML documents? 如何使用docx4j阅读word文档并使用所有样式获取部分文档 - How to read word document and get parts of it with all styles using docx4j 如何将网站的页眉和页脚存储在一个位置? - How do I store my websites header and footer in one location? 如何将内容居中与页眉和页脚相同? - How do I center the content the same as the header and footer? 我如何通过JavaScript和jQuery在word文档的标题中插入图像 - how i can insert image in header of word document by JavaScript and jQuery 如何仅在正文上启用跳动过度滚动(不包括页眉和页脚)? - How do I enable bounce overscroll on the body only (not header and footer)? 我如何重新定位固定的页眉和页脚? - how do i re-position fixed Header & Footer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM