Adding dynamic header/footer to Docs

北城以北 提交于 2019-12-11 02:21:35

问题


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.


回答1:


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"))
}

Second Page

Third Page

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.



来源:https://stackoverflow.com/questions/42515622/adding-dynamic-header-footer-to-docs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!