Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Google Apps脚本在文档中获取多个页眉/页脚_Javascript_Google Apps Script_Google Sheets_Google Docs Api - Fatal编程技术网

Javascript 如何使用Google Apps脚本在文档中获取多个页眉/页脚

Javascript 如何使用Google Apps脚本在文档中获取多个页眉/页脚,javascript,google-apps-script,google-sheets,google-docs-api,Javascript,Google Apps Script,Google Sheets,Google Docs Api,我正在尝试替换Google文档标题中的一个文本,该文档标题中的“第一页页眉/页脚不同”处于活动状态。我成功地替换了除第一页之外的任何其他页眉中的文本。 我看了文档,但没有看到如何做。我甚至尝试过使用“getHeaders()”(复数形式),但该类不存在。 如何替换第一页页眉/页脚中的文本 谢谢 伊万 这将指向第一页的标题。getChild(2)中的“2”可能会改变,也可能不会改变,但我在这个答案的第三个代码块上添加了一个函数,seechilds() 如果要替换文档中字符串的所有实例,请将其与

我正在尝试替换Google文档标题中的一个文本,该文档标题中的“第一页页眉/页脚不同”处于活动状态。我成功地替换了除第一页之外的任何其他页眉中的文本。

我看了文档,但没有看到如何做。我甚至尝试过使用“getHeaders()”(复数形式),但该类不存在。 如何替换第一页页眉/页脚中的文本

谢谢

伊万

这将指向第一页的标题。
getChild(2)
中的“2”可能会改变,也可能不会改变,但我在这个答案的第三个代码块上添加了一个函数,
seechilds()

如果要替换文档中字符串的所有实例,请将其与
replaceText()

如果您想知道
getChild(x)
页脚的x,请

function seeChildren(){
  var doc = DocumentApp.getActiveDocument();
  var bod = doc.getBody();
  var fol = bod.getParent();
  for (i = 0; i<fol.getNumChildren(); i++){
    var child = fol.getChild(i);
    bod.appendParagraph(child + ": Index " + fol.getChildIndex(child));
  }
}
函数见children(){
var doc=DocumentApp.getActiveDocument();
var bod=doc.getBody();
var fol=bod.getParent();
对于(i=0;i
这将指向第一个不同页面的标题。

中有一个问题。您可以向上投票该问题。
copyHeader.getParent().getChild(2); //I'm using your variable
copyHeader.getParent(); /*this points to the whole document (unless the 
                          header's parents is not the whole)*/
//getbody(), getfooter(), etc (i.e. siblings of header) should work
function seeChildren(){
  var doc = DocumentApp.getActiveDocument();
  var bod = doc.getBody();
  var fol = bod.getParent();
  for (i = 0; i<fol.getNumChildren(); i++){
    var child = fol.getChild(i);
    bod.appendParagraph(child + ": Index " + fol.getChildIndex(child));
  }
}
copyHeader.getParent().getChild(3).replaceText('current text','new text');