首页 > 解决方案 > 如何使用 Google App Script 在 google 电子表格上获取毫秒详细信息

问题描述

这是我正在更新谷歌电子表格的应用程序脚本功能。我正在获取由“/”分隔的所有 Html 用户填充数据。我正在从 Html 页面向谷歌电子表格发送响应,并希望获取日期对象的毫秒详细信息,以避免覆盖。

Let's say if multiple people are submitting at once then, I can get only 
the last entry because the date object is created with mm/dd/yyyy hh:mm:ss 
format and if multiple people are submitting at the same instance of time 
like ( 4 people are submitting at 03/03/2020 04:55:55) then I will be 
getting the last submitted record and other records will be overwritten by 
the last record. 

Can anyone of you help me with this?  How should I solve this requirement?

请从我正在调用 google app script API 的 HTML 页面中找到我的 javascript 函数,以运行在 app 脚本中编写的函数 userClick。 function sendData(u_wk_Det) { google.script.run.withSuccessHandler(function(response) {console.log(response);}) .withFailureHandler(function(err){console.log(err);}) .userClick(u_wk_Det); }

/*code shown below is my app script function using which I am updating the google spreadsheets.*/

`function userClick(u_wk_det)
      {
       Logger.log('table data - ');
       var ss = 
       SpreadsheetApp.openById('sheetid').getSheetByName('Sheet2');
       var Srow = 2;
       var Lrow = ss.getLastRow();
       var Lcol = ss.getLastColumn();
       var data = ss.getRange(2, 1, Lrow  , Lcol).getValues().filter(function(o) 
       {return o !=="" });
       for(i in data)
       {  

        var j=i;
        j++;
        j++;
        var Crow = data[i];
        if (Crow[0]=='')
        {
             var dt = new Date();
             Logger.log(dt);
             Logger.log(Crow[0]);
              if(u_wk_det!=="")
                { 
                    var user_week_details = u_wk_det.split("/"); 
                    ss.getRange(j,1).setValue(dt);
                    ss.getRange(j,2).setValue(user_week_details[0]);
                    ss.getRange(j,3).setValue(user_week_details[1]);
                    ss.getRange(j,4).setValue(user_week_details[2]);
                }
        }
    }
}`

标签: google-apps-scriptgoogle-sheets-api

解决方案


推荐阅读