footer.replaceText() 没有用新文本替换我的占位符

footer.replaceText() does not replace my placeholder with new text

谁能解释为什么 footer.replaceText() 没有用新文本替换我的占位符。它适用于页眉和正文。

//opens the master report document which is now saved as the student's name and gets the contents of the header
let header = DocumentApp.openById(documentId).getHeader()

    //opens the master report document which is now saved as the student's name and gets the contents of the body
    let body = DocumentApp.openById(documentId).getBody()
    
//opens the master report document which is now saved as the student's name and gets the contents of the footer
let footer = DocumentApp.openById(documentId).getFooter()

header.replaceText('{{First Name}}', row[studentDetails.firstName])
body.replaceText('{{Maths Attainment}}', row[studentDetails.mathsAttainment])
footer.replaceText('{{Class Teacher}}', row[studentDetails.classTeacher])

我似乎无法在 Stack Overflow 上找到有效的答案。

如果您使用 'Different first page' 选项,您将无法以常用(已记录)方式获取第一页的页脚和页眉。

基于 尝试以这种 'secret' 方式获取它们:

let first_header = header.getParent().getChild(3);
let first_footer = header.getParent().getChild(4);

然后您可以像往常一样更改它们:

first_header.replaceText('{{First Name}}', row[studentDetails.firstName]);
first_footer.replaceText('{{Class Teacher}}', row[studentDetails.classTeacher]);