Google App脚本|页眉和页脚|替换文字 [英] Google App Script | Headers and Footers | Replace text
问题描述
我正在尝试构建一个脚本来替换Google文档中的某些数据.我只是发现一个问题.该脚本适用于从第二页到最后一页的所有正文和页脚.我的首页页脚设置为与其他页脚不同,但是我找不到修改其内容的方法.
I'm trying to built a script that replace some Data in a Google Document. I'm just observing a problem. The script works well for all the body and the footers from the 2nd to the last page. My first page footer is set as different than the others but i couldn't find a way to modify its content.
您有什么解决方案吗?顺便说一句,我正在寻找一种在脚本末尾在浏览器中打开新文档的方法.有什么解决办法吗?我的脚本有一部分.
Do you have any solutions ? By the way, I'm looking for a way to open the new document in my browser at the end of the script. Any solutions too ? There's a part of my script.
var documentId = DriveApp.getFileById('1mh8yjFpy7NcjB8meXWvn1SKQofjSMcFdPqWBe4GoC14').makeCopy().getId();
var body = DocumentApp.openById(documentId).getBody();
var footer = DocumentApp.openById(documentId).getFooter();
DriveApp.getFileById(documentId).setName('RM_' + RM + '_' + IDEtude + "_" + Prenom + "_" + Nom);
footer.replaceText("{RM_REF}", RM);
footer.replaceText("{PROJECT_REF}", IDEtude);
body.replaceText("{RM_REF}", RM);
body.replaceText("{PROJECT_REF}", IDEtude);
body.replaceText("{NumeroBA}", numBA);
body.replaceText('{PrenomNom}', Prenom + " " +Nom);
body.replaceText('{adresse}', Adresse);
body.replaceText('{code postal et ville}', CP);
body.replaceText('{numero de telephone}', NumTel);
body.replaceText('{CLIENT_COMPANY}', NomClient);
body.replaceText('{DatedeFin}', DatedeFin);
body.replaceText('{DatedeDebut}', DatedeDebut);
body.replaceText('{FaitLe}',Date);
body.replaceText('{Ville}',VilleCdP);
感谢您的帮助!
推荐答案
尝试在第37行之后的 Code.gs
中添加以下三行:
Try to add these three lines in your Code.gs
after the line 37:
first_footer = footer.getParent().getChild(3);
first_footer.replaceText("{RM_REF}", RM);
first_footer.replaceText("{PROJECT_REF}", IDEtude);
... getParent().getChild(3)
—是一种在不同首页"上访问页脚的技巧(可能是您的情况)
...getParent().getChild(3)
— is the hack to get access to a footer on a 'different first page' (probably it's your case)
这篇关于Google App脚本|页眉和页脚|替换文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!