google-apps-script - footer.replaceText() 不会用新文本替换我的占位符
问题描述
谁能解释为什么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 上找到有效的答案。
解决方案
如果您使用“不同的第一页”选项,则无法以常用(记录的)方式获取第一页的页脚和页眉。
根据这个答案,尝试以这种“秘密”方式让他们:
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]);
推荐阅读
- sql - 将字符串转换为日期 Google Big Query
- amazon-web-services - 当 EBS 快照的权限发生更改时,Cloudwatch 事件会触发 lambda
- javascript - 使用 lodash 链过滤和返回父对象
- c# - 如何创建 PFX 文件以在 Bit.IdentityServer 中使用?
- javascript - 如果值动态更改,则触发函数
- c# - DLL 项目 - 知道调用它的环境是什么?(网络/赢/cmd)
- python-3.x - 将主 ID 添加到子级
- postgresql - 如何在一天中的 2 个特定时间之间进行查询
- java - 如何测试从服务器拦截器设置的上下文键值
- swift - Swift 5.0:不推荐使用“withUnsafeBytes”:使用“withUnsafeBytes”
(...)