问题描述
我想知道是否有一种方法可以向文档中添加动态页眉或页脚,即在页脚中放置每个页面都不同的页面标题".
I'm wondering if there is a way to add dynamic headers or footers to a document, i.e. putting a "Page Title" in the footer that is different for every page.
我知道编辑内置页眉或页脚将反映在每个页面上.我想知道是否有人想办法通过访问页面的第一行/最后一行并在其中插入文本来强制"它,或者是否存在另一种动态更新页面的方法.
I understand that editing the built-in header or footer would be reflected on every page. I'm wondering if anyone has thought of a workaround to either "force" it by accessing the first/last line on a page and inserting text there, or if there is another way to dynamically update the page.
推荐答案
AFAIK,此功能尚不可用.上有一个未完成的问题无法可靠地访问首页和其他页面的页眉/页脚信息.
AFAIK, this is not yet available. There is an open issue on can't reliably access first page vs other pages header / footer info.
我已经在此处使用代码来列出文档的子代.
I've used the codes here, to list the document's children.
DocumentBodySection: Index 0
HeaderSection: Index 1
FooterSection: Index 2
HeaderSection: Index 3
FooterSection: Index 4
此功能更改所选子项的文本.
This function change the text of the selected child.
function myFunction() {
var copyDoc = DocumentApp.getActiveDocument();
var footer = copyDoc.getFooter();
Logger.log(footer.getParent().getChild(2).asText().setText("Test"))
}
第二页
第三页
根据此博客,您只能在首页中设置其他页眉/页脚.所提供的未解决问题链接还指出,由于不可用,只能对其进行手动检查.
Changing a footer section will apply to all footer section, according to this blog you can only set a different header/footer in the first page. The provided open issue link also states that it can only be checked manually as it is not available.
这篇关于向文档添加动态页眉/页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!