获取单元格值作为函数值

时间:2019-08-06 20:34:14

标签: google-apps-script google-sheets

我尝试创建一个Google表格脚本,将一个列表复制到另一个表中(新表的名称在单元格D5中)。复制确实可以,但是我必须在脚本中键入tablename手册。表名必须在代码中的“ [这里]”点。

我创建了一个变量,其值为“ D5”。之后,他没有找到桌子。

function alleDaten() {

  var sheet1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Aktueller_Fall");

var sheet2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("[here]");

  sheet1.getRange(10, 2, sheet1.getLastRow(), sheet1.getLastColumn()).copyTo(sheet2.getRange(sheet2.getLastRow()+1,1));
}

1 个答案:

答案 0 :(得分:0)

function alleDaten() {
  var sheet1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Aktueller_Fall");

在此处提示:

  var sheet2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("[here]");//get the sheetname from the prompt response
  sheet1.getRange(10, 2, sheet1.getLastRow(), sheet1.getLastColumn()).copyTo(sheet2.getRange(sheet2.getLastRow()+1,1));
}

赞:

function CopyDataToAnotherSheet() {
  var sheet1=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
  var resp=SpreadsheetApp.getUi().prompt("Provide Sheet Name", SpreadsheetApp.getUi().ButtonSet.OK_CANCEL)
  if(resp.getSelectedButton()==SpreadsheetApp.getUi().Button.OK) {
    var sheet2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(resp.getResponseText());
    sheet1.getRange(10, 2, sheet1.getLastRow(), sheet1.getLastColumn()).copyTo(sheet2.getRange(sheet2.getLastRow()+1,1));
  }
}