Google apps script 将粗体文本从电子表格中粘贴到文档中

Google apps script 将粗体文本从电子表格中粘贴到文档中,google-apps-script,google-sheets,google-docs,Google Apps Script,Google Sheets,Google Docs,因此,我一直在解决一个问题,即从电子表格中提取结构化数据,然后使用应用程序脚本将其插入到谷歌文档的模板中 我让它简单地作为串联字符串工作,但我正试图用BODY类来完成,所以如果我想把最终产品放到Gmail中,可能会更容易。或者如果我想保留表结构 所以,除了这一段代码之外,一切都很好。我正在与挫折作斗争。这是一个奇怪的语法,因为它是一个布尔运算,对吗 这就是我所拥有的,我认为很容易摸索: for(var i = 0; i < num; i++) { var songName

因此,我一直在解决一个问题,即从电子表格中提取结构化数据,然后使用应用程序脚本将其插入到谷歌文档的模板中

我让它简单地作为串联字符串工作,但我正试图用BODY类来完成,所以如果我想把最终产品放到Gmail中,可能会更容易。或者如果我想保留表结构

所以,除了这一段代码之外,一切都很好。我正在与挫折作斗争。这是一个奇怪的语法,因为它是一个布尔运算,对吗

这就是我所拥有的,我认为很容易摸索:

    for(var i = 0; i < num; i++) {
    var songName = String(dataArray[i][1]);
    var sWs = String(dataArray[i][2]);
    var pub =  String(dataArray[i][3]);
newText.editAsText().appendText('SONG NAME:'+ nLi).setBold(true);
newText.editAsText().appendText(songName + brk).setBold(false);
newText.editAsText().appendText('SONGWRITER(S):' + nLi);
把挫折看作是设置然后解除旗帜

两者都不起作用。

我更喜欢使用样式:

function addboldtext() {
  const doc=DocumentApp.getActiveDocument();
  const body=doc.getBody();
  const style1={};
    style1[DocumentApp.Attribute.BOLD]=true;
    style1[DocumentApp.Attribute.FOREGROUND_COLOR]='#000000';//you can add all of the attributes that you wish
  body.appendParagraph("This is text").setAttributes(style1)
}

这种格式是荒谬的。有趣。我使用:
const-hOne={};hOne[DocumentApp.Attribute.BOLD]=true;hOne[DocumentApp.Attribute.FONT\u SIZE]=10;常数hTwo={};hTwo[DocumentApp.Attribute.BOLD]=false;hTwo[DocumentApp.Attribute.FONT\u SIZE]=9;newText.editAsText().appendText('歌曲名称:'+nLi).setAttributes(hOne)newText.editAsText().appendText(歌曲名称+brk).setAttributes(hTwo);}body.replaceText(“##XXXX##”,newText.getText())我想知道使用getText是否会删除它。也许我应该用另一个替代品Hello@EzraGreene,您的评论是您实现的解决方案吗?如果是的话,你能把它作为一个答案吗?谢谢:)不,不是。但我希望能得到一些帮助,至少,重新格式化是易读的。如果你建议在注释中不使用格式化代码,你所说的
重新格式化它是什么意思。但通常情况下,我们更希望你在问题中加入这种类型或代码。我甚至不知道我们在讨论什么。1.我的代码仍然不起作用。2.我不能很好地格式化我的评论。这两件事是真的。除此之外,这对我来说是一个混乱。
function addboldtext() {
  const doc=DocumentApp.getActiveDocument();
  const body=doc.getBody();
  const style1={};
    style1[DocumentApp.Attribute.BOLD]=true;
    style1[DocumentApp.Attribute.FOREGROUND_COLOR]='#000000';//you can add all of the attributes that you wish
  body.appendParagraph("This is text").setAttributes(style1)
}