使用Google App Scrips生成输入消息

时间:2015-05-14 05:53:48

标签: google-apps-script google-sheets

我基本上想要为我们的游戏社区设置一个真正帮助我们的设置。我有这样的想法,如果你把一个特定值放到Google电子表格的单元格中,它会给客户端弹出框说些什么。

现在,我们在当前的电子表格中使用了您可以在此处看到的内容:" https://docs.google.com/spreadsheets/d/1QBVvQkkmLJ3Ro2uHAmQm2yulmJ8Tg38p5Ke3YIe-FwI/edit#gid=1161230471"。我们在课程部分有数据验证。现在基本上,我想要发生的是当一个人从该下拉列表中选择某个值时,它会在屏幕上放置一个弹出框来解释有关该课程的关键信息。

这甚至可能吗?

肖恩。

1 个答案:

答案 0 :(得分:0)

这是你如何做到的。根据需要添加尽可能多的“else if”功能。我把它格式化了,你很容易编辑

function onEdit(e) {
  var cell = e.range;
  var cellColumn = cell.getColumn();
  var cellSheet = cell.getSheet().getName();
  var cellValue = e.value;
  var sheet = "System_Info";   //This is here to ignore the System info sheet

  if (cellSheet !== sheet && cellColumn === 4) {
    if (cellValue === "PT1 - Induction Training") {
      Browser.msgBox("This is a training course. (put your message text here)");  //Add the course name and the message that you want to popup. Course name should be exactly the same as in the list (case sensitive)
    } 

    else if (cellValue === "Course 2 name") {
      Browser.msgBox("Pop-up box message");  //// add as many "else if" conditions as you want"
    } else if (cellValue === "Course 3 name") {
      Browser.msgBox("Pop-up box message");   
    } else if (cellValue === "Course 4 name") {
      Browser.msgBox("Pop-up box message");   
    } else if (cellValue === "Course 5 name") {
      Browser.msgBox("Pop-up box message");   
    } else if (cellValue === "Course 6 name") {
      Browser.msgBox("Pop-up box message");   
    } else if (cellValue === "Course 7 name") {
      Browser.msgBox("Pop-up box message");   
    } else if (cellValue === "Course 8 name") {
      Browser.msgBox("Pop-up box message");   
    } else if (cellValue === "Course 9 name") {
      Browser.msgBox("Pop-up box message");   
    } else if (cellValue === "Course 10 name") {
      Browser.msgBox("Pop-up box message");   
    } 


    else if (cellValue === undefined) {  }
    else {
      Browser.msgBox("Please choose a valid course from the lsit");   //This is in case they put a wrong course name
    }
  }
}

<强>更新 如果要在多个列上执行此操作,请更改

if (cellSheet !== sheet && cellColumn === 4) {

if (cellSheet !== sheet){
  if {cellColumn === 4 || cellColumn === 5) {
    //the rest of your code
  }
}