Google 脚本:与脚注交互

Google Script: interacting with footnotes

我是 google 脚本(和 javascript)的(非常)新手,我正在尝试编写一个脚本来修改文档中脚注的字体大小。不幸的是,我找不到与文档中的脚注交互的指导。

到目前为止,我已尝试从 基础开始工作,但出现错误

Cannot find function setAttributes in object function getFootnoteContents() {/* */}.

我不是在寻找 "solve this for me answer",可能只是一些关于如何处理脚注内容或在某个地方开始朝那个方向学习的指南。

我的代码如下:

function footSize() {
  var doc = DocumentApp.getActiveDocument();
  var footnotes = doc.getFootnotes();
  var style = {};
  style[DocumentApp.Attribute.FONT_SIZE] = 18;
  for(var i in footnotes ){
  Logger.log(footnotes[i].getFootnoteContents.setAttribute(style));
  }
}

解决方案使用 Henrique 的答案:

function footSize() {
 var footnote = DocumentApp.getActiveDocument().getFootnotes();
 var style = {};
 style[DocumentApp.Attribute.FONT_SIZE] = 18;
 for(var i in footnote){
   footnote[i].getFootnoteContents().setAttributes(style);
   }
 }

getFootnoteContent 是一个检索脚注部分的函数,因此您可以操纵其内容。您可以尝试在内容中设置此属性(您错过了调用内容函数的括号)或脚注本身。

footnotes[i].setAttribute(style); //or
footnotes[i].getFootnoteContents().setAttribute(style); //note the parenthesis

--给你编辑地址

编辑后不会弹出此错误。您甚至不再引用 getFootnoteContents。如果设置样式在脚注对象本身不起作用,请尝试在其部分设置(第二个建议)。