Take mail ID by pressing a button in googlesheet

前端 未结 1 1856
野的像风
野的像风 2021-01-26 11:50

Can someone suggest me a Google Script that will make a button that will get the mail ID of the person and put it into a specified Google sheet.

相关标签:
1条回答
  • 2021-01-26 12:20

    This would be your script. Create a drawing like a button, via the little 3 dots you can assign it to a script, type: getEmail.

    If the user is a gmail user it will append the value to the target sheet. If not then it opens a prompt where someone can enter the email.

    function getEmail(){
      const ui = SpreadsheetApp.getUi();
      const ss = SpreadsheetApp.getActiveSpreadsheet();
      const targetSheet = ss.getSheetByName("targetsheet"); // change to desire
      const userMail = Session.getActiveUser().getEmail();
    
      if (userMail == null){
        targetSheet.appendRow(ui.prompt("Enter email").getResponseText());
      } else {
        targetSheet.appendRow([userMail]);
      }
    }
    
    0 讨论(0)
提交回复
热议问题