Using Google App Scrips to produce Input Messages

2019-09-05 15:02发布

问题:

I basically want to have a set-up for our gaming community that would really help us out. I have this idea that if you put a certain value into a cell on a Google Spreadsheet, it would give a client-side pop-up box saying something.

Now in the current spreadsheet we use which you can see here: "https://docs.google.com/spreadsheets/d/1QBVvQkkmLJ3Ro2uHAmQm2yulmJ8Tg38p5Ke3YIe-FwI/edit#gid=1161230471". We have Data Validation under the course section. Now essentially, what I want to happen is when a person selects a certain value from that drop down list, it will put a Pop-Up box on their screen explaining key information about the course.

Is this even possible?

Shaun.

回答1:

Here is how you do it. Add as many "else if" functions as you want. I formatted it in the it would be easy for you to edit

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
    }
  }
}

UPDATE: If you want to do this on multiple columns, change

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

To

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