【问题标题】:Google Apps Script code to set value in the next blank row用于在下一个空白行中设置值的 Google Apps 脚本代码
【发布时间】:2016-09-25 09:43:14
【问题描述】:

我试图通过创建一个 Google Apps 脚本来简化我的生活,该脚本在我的驱动器中复制另一个模板表,然后将 URL 和该新表的名称粘贴到我运行脚本的原始表中。

我在下面编写的脚本就是这样做的。但是,每次运行脚本时,新的 URL 值总是粘贴在“A12”中。如何让脚本将该值粘贴到下一个单元格?

function saveAsSpreadsheet£(){ 
  var sheet = SpreadsheetApp.getActiveSpreadsheet(); 
  var ss = sheet.getSheets()[0];
  var range = ss.getRange("I6");
  var values = ss.getRange("A12");
  var data = range.getValue();
  var destFolder = DriveApp.getFolderById("xxxxxxxxxxxxxxxxxxx");
  var makecopyurl = DriveApp.getFileById(sheet.getId()).makeCopy(data + " Management Workbook", destFolder).getUrl();

  var npo = '=hyperlink("' + (makecopyurl) + '";"' + data  + '")';
  values.setValue(npo)}

这是一个示例电子表格的a link

【问题讨论】:

  • 您应该将 ss.getRange("A12") 中的 A12 替换为您希望粘贴新链接的单元格。

标签: google-apps-script google-sheets


【解决方案1】:

如果“下一个单元格”是最后一行的正下方,您可以使用 getLastRow 并使用 getRange(row,column):

替换

var values = ss.getRange("A12");

通过

var lastRow = ss.getLastRow();
var values = ss.getRange(lastRow + 1, 1);

【讨论】:

    【解决方案2】:

    你可以使用appendRow()

    此方法查找包含数据的最后一行,然后追加到下一行。

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheets()[0];
    
    // Appends a new row with 3 columns to the bottom of the
    // spreadsheet containing the values in the array
    sheet.appendRow(["a man", "a plan", "panama"]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      相关资源
      最近更新 更多