Google apps script 如何使用javascript从HTML向现有Google电子表格添加行(数据)

Google apps script 如何使用javascript从HTML向现有Google电子表格添加行(数据),google-apps-script,google-spreadsheet-api,Google Apps Script,Google Spreadsheet Api,我有一个用于捕获电子邮件地址的输入文本框。提交后,我想将电子邮件地址以HTML格式添加到后端现有的Google电子表格中。任何人都可以帮助我。提前感谢 代码 html: javascript: <script type="text/javascript"> function validateEmail(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)

我有一个用于捕获电子邮件地址的输入文本框。提交后,我想将电子邮件地址以HTML格式添加到后端现有的Google电子表格中。任何人都可以帮助我。提前感谢

代码 html:


javascript:

<script type="text/javascript">
function validateEmail(email) {
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
    }

    function addEmail(){
        var email_id = $('#email_id').val();
        if ((email_id != "") && (validateEmail(email_id))){
            alert("valid");
            //Here i want to save in Google Spreadsheet
        }
        else {
            if(email_id == ""){
                alert('Please enter Email ID');
                return false;
            }
            alert('INvalid Email ID');
        }
        $('#email_id').val('');
    }
</script>

功能验证电子邮件(电子邮件){
变量re=/^([^()[\]\\,;:\s@\“]+(\.[^()[\]\,;:\s@\“]+)*)(\'+\”)(\[[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[1,3}.[0-9]{1,3}.];
返回重新测试(电子邮件);
}
函数addEmail(){
var email_id=$('#email_id').val();
if((email\u id!=“”)和&(validateEmail(email\u id))){
警报(“有效”);
//在这里,我想保存在谷歌电子表格
}
否则{
如果(电子邮件id==“”){
警报(“请输入电子邮件ID”);
返回false;
}
警报(“无效的电子邮件ID”);
}
$('#email_id').val('');
}

如果您使用的是谷歌应用程序脚本,则必须使用:

google.script.run.gsFunctionNameInAppsScript()

如果未使用应用程序脚本,则必须使用特定于服务器端语言的其他API

<script>
  function onSuccess(argReturnValue) {
    if (argReturnValue === true) {
      alert('The email was saved to the spreadsheet!');
    };
  };

  function addEmail(){
    . . . . Your existing code . . . 
    google.script.run.withSuccessHandler(onSuccess)
      .addRowToSpreadsheet(email_id);
</script>

正在使用什么后端技术。发布您已经尝试过的代码片段。
<script>
  function onSuccess(argReturnValue) {
    if (argReturnValue === true) {
      alert('The email was saved to the spreadsheet!');
    };
  };

  function addEmail(){
    . . . . Your existing code . . . 
    google.script.run.withSuccessHandler(onSuccess)
      .addRowToSpreadsheet(email_id);
</script>
function addRowToSpreadsheet(argTheEmail) {
  var thisSS = SpreadsheetApp.getActiveSpreadsheet();
  var theSheet = thisSS.getSheetByName("Email_List");
  theSheet.appendRow([argTheEmail]);
  return true;
}