如何在sheet.appendRow中创建“漂亮的名字”?

时间:2013-02-19 19:21:50

标签: google-apps-script google-sheets

此代码有效,但是,我希望为工作表的网址显示漂亮的名称,例如link,而不是显示url。我知道如何用=hyperlink做到这一点,但在这里,我感到茫然:

  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.clearContents();
  sheet.appendRow(["Link", "Name", "Type", "ID"]);
  for (var i = 0; i < contents.length; i++) {
    file = contents[i];
    var value1,value2,value3;
    if (file.getFileType()==DocsList.FileType.SPREADSHEET) {
      var otherSheet = SpreadsheetApp.open(file).getSheetByName("Sheet1");
      value1 = otherSheet.getRange('B2').getValue();
      value2 = otherSheet.getRange('B7').getValue();
      value3 = otherSheet.getRange('B3').getValue();
    } else {
      value1 = null; value2 = null; value3 = null; value4 = null;
    }
    sheet.appendRow([ file.getUrl(),value1,value2,value3,value4]);
  }
};

1 个答案:

答案 0 :(得分:1)

我明白了!我补充说:

var name = "link"; 
var semi = ";";
var hyp = "=hyperlink(\""; var quot = "\""; var clos = ")";
var pp = hyp + url + quot + semi + quot + name + quot + clos;

然后将其更改为sheet.appendRow)[link, value1...