问题
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:
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]);
}
}
来源:https://stackoverflow.com/questions/62222770/take-mail-id-by-pressing-a-button-in-googlesheet