尝试在Google工作表底部添加数据

时间:2018-03-21 09:11:17

标签: google-apps-script google-sheets

我正在尝试每天收集一个数据范围并将其放在同一个工作表的底部,每天添加一个新行,但我的代码只是将数据放在下一行的顶部而不是保留旧的,把它放在下一行:

function recordHistory() {

 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheetByName("RECEIPT TRACKER");
 var sh = ss.insertRowAfter(1);
 var source = sheet.getRange("b33:n33");
 var freeze = sh.getRange("b33:n33");
 var values = source.getValues();
 values[0][0] = new Date();
 sheet.appendRow(values[0]);
};

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:0)

您的问题有点不清楚,但从查看您的代码我认为这是您要实现的目标。

function recordHistory() {
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var sheet = ss.getSheetByName("RECEIPT TRACKER"); 
  var source = sheet.getRange("b33:n33").getValues(); // Get the values in Row 33 cols B:N
  source[0].splice(0,0,new Date); // Insert a date object at the start of array
  sheet.appendRow(source[0]); // Append a new row at the bottom of the data range with the values from above 
};

如果这不正确,请提供您想要实现的前后截图。