Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 倒计时计时器启动/停止/重置按钮,带有应用程序脚本到谷歌工作表_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 倒计时计时器启动/停止/重置按钮,带有应用程序脚本到谷歌工作表

Google apps script 倒计时计时器启动/停止/重置按钮,带有应用程序脚本到谷歌工作表,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我有一些关于谷歌表单上带有开始/停止/重置命令按钮的倒计时计时器的问题。如何使用google apps脚本为其编写脚本,并使用start/stop/reset按钮将命令放入google工作表。用于收集电子表格数据的Javascript计时器 我为我的一个项目建立了这个测试设置。以下是datatimer.html: <!DOCTYPE html> <html> <head> <base target="_top"> <lin

我有一些关于谷歌表单上带有开始/停止/重置命令按钮的倒计时计时器的问题。如何使用google apps脚本为其编写脚本,并使用start/stop/reset按钮将命令放入google工作表。

用于收集电子表格数据的Javascript计时器 我为我的一个项目建立了这个测试设置。以下是datatimer.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <style>
      #my_block{border:2px solid black;background-color:rgba(0,150,255,0.2);padding:10px 10px 10px 10px;}
      #conv_block{border: 1px solid black;padding:10px 10px 10px 10px;}
      .bttn_block{padding:5px 5px 0px 0px;}
      .sndr_block {border:1px solid rgba(0,150,0,0.5);background-color:rgba(150,150,0,0.2);margin-bottom:2px;}
    </style>
  </head>
  <body>
  <form>
    <div id="my_block" class="block form-group">
      <div class="sndr_block">
        <div id="myClock"></div>
        <br />Timer Duration(minutes):
        <br /><input id="txt1" type="text" size="4" class="action"/>
        <select id="sel1" onChange="loadTxt('sel1','txt1');">
          <option value="90000">1.5</option>
          <option value="96000">1.6</option>
          <option value="102000">1.7</option>
          <option value="108000">1.8</option>
          <option value="114000">1.9</option>
          <option value="120000" selected>2.0</option>
          <option value="126000">2.1</option>
          <option value="132000">2.2</option>
          <option value="138000">2.3</option>
          <option value="144000">2.4</option>
        </select>
        <div id="cntdiv"></div>
        <br /><strong>Timer Controls</strong>
        <div class="bttn_block"><input type="button" value="Start" name="startShow" id="startShow" onClick="startmytimer();" class="red" /></div>
        <div class="bttn_block"><input type="button" value="Stop" name="stopTimer" id="stopTimer" class="red" /></div>
        <div class="bttn_block"><input type="button" value="Single Ping" name="changedata" id="chgData" class="red" onClick="changeData();" /></div>

      </div>
      <div id="btn-bar">
        <br /><input type="button" value="Exit" onClick="google.script.host.close();" class="green" />
      </div>
    </div>
  </form>
    <script>
    var idx=1;
    var myInterval='';
    var cnt=0;
      $(function() {
        $('#startTimer').click(startmytimer);
        $('#stopTimer').click(stopTimer);
        $('#txt1').val('120000');
        startTime();
      });

      function startTime(){
        var today = new Date();
        var h = today.getHours();
        var m = today.getMinutes();
        var s = today.getSeconds();
        m = checkTime(m);
        s = checkTime(s);
        document.getElementById('myClock').innerHTML =
        h + ":" + m + ":" + s;
        var t = setTimeout(startTime, 500);
      }

      function checkTime(i){
        if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
        return i;
      }

      function startmytimer(){
        document.getElementById('cntdiv').innerHTML='<strong>Timer Started:</strong> ' + document.getElementById('myClock').innerHTML;
        myInterval=setInterval(changeData, Number($('#txt1').val()));
      }

      function stopTimer(){
        document.getElementById('cntdiv').innerHTML='Timer Stopped';
        clearInterval(myInterval);
      }

      function loadTxt(from,to){
        document.getElementById(to).value = document.getElementById(from).value;
      }

      function changeData(){
        $('#txt1').css('background','#ffffcc');
        google.script.run
        .withSuccessHandler(updateDisplay)
        .changeData();
      }

      function updateDisplay(t){
        $('#txt1').css('background','#ffffff');
        document.getElementById('cntdiv').innerHTML='<strong>Timer Running:</strong> Count= ' + ++cnt + ' <strong>Time:</strong> ' + t;
      }

     console.log('My Code');
   </script>
  </body>
</html>
我只是在看一张有谷歌金融细胞功能的表格的输出。但是你可以随时打电话给任何你想要的人

下面是该对话框的外观:

用于从电子表格收集数据的Javascript计时器 我为我的一个项目建立了这个测试设置。以下是datatimer.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <style>
      #my_block{border:2px solid black;background-color:rgba(0,150,255,0.2);padding:10px 10px 10px 10px;}
      #conv_block{border: 1px solid black;padding:10px 10px 10px 10px;}
      .bttn_block{padding:5px 5px 0px 0px;}
      .sndr_block {border:1px solid rgba(0,150,0,0.5);background-color:rgba(150,150,0,0.2);margin-bottom:2px;}
    </style>
  </head>
  <body>
  <form>
    <div id="my_block" class="block form-group">
      <div class="sndr_block">
        <div id="myClock"></div>
        <br />Timer Duration(minutes):
        <br /><input id="txt1" type="text" size="4" class="action"/>
        <select id="sel1" onChange="loadTxt('sel1','txt1');">
          <option value="90000">1.5</option>
          <option value="96000">1.6</option>
          <option value="102000">1.7</option>
          <option value="108000">1.8</option>
          <option value="114000">1.9</option>
          <option value="120000" selected>2.0</option>
          <option value="126000">2.1</option>
          <option value="132000">2.2</option>
          <option value="138000">2.3</option>
          <option value="144000">2.4</option>
        </select>
        <div id="cntdiv"></div>
        <br /><strong>Timer Controls</strong>
        <div class="bttn_block"><input type="button" value="Start" name="startShow" id="startShow" onClick="startmytimer();" class="red" /></div>
        <div class="bttn_block"><input type="button" value="Stop" name="stopTimer" id="stopTimer" class="red" /></div>
        <div class="bttn_block"><input type="button" value="Single Ping" name="changedata" id="chgData" class="red" onClick="changeData();" /></div>

      </div>
      <div id="btn-bar">
        <br /><input type="button" value="Exit" onClick="google.script.host.close();" class="green" />
      </div>
    </div>
  </form>
    <script>
    var idx=1;
    var myInterval='';
    var cnt=0;
      $(function() {
        $('#startTimer').click(startmytimer);
        $('#stopTimer').click(stopTimer);
        $('#txt1').val('120000');
        startTime();
      });

      function startTime(){
        var today = new Date();
        var h = today.getHours();
        var m = today.getMinutes();
        var s = today.getSeconds();
        m = checkTime(m);
        s = checkTime(s);
        document.getElementById('myClock').innerHTML =
        h + ":" + m + ":" + s;
        var t = setTimeout(startTime, 500);
      }

      function checkTime(i){
        if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
        return i;
      }

      function startmytimer(){
        document.getElementById('cntdiv').innerHTML='<strong>Timer Started:</strong> ' + document.getElementById('myClock').innerHTML;
        myInterval=setInterval(changeData, Number($('#txt1').val()));
      }

      function stopTimer(){
        document.getElementById('cntdiv').innerHTML='Timer Stopped';
        clearInterval(myInterval);
      }

      function loadTxt(from,to){
        document.getElementById(to).value = document.getElementById(from).value;
      }

      function changeData(){
        $('#txt1').css('background','#ffffcc');
        google.script.run
        .withSuccessHandler(updateDisplay)
        .changeData();
      }

      function updateDisplay(t){
        $('#txt1').css('background','#ffffff');
        document.getElementById('cntdiv').innerHTML='<strong>Timer Running:</strong> Count= ' + ++cnt + ' <strong>Time:</strong> ' + t;
      }

     console.log('My Code');
   </script>
  </body>
</html>
我只是在看一张有谷歌金融细胞功能的表格的输出。但是你可以随时打电话给任何你想要的人

下面是该对话框的外观:

您可以在谷歌表单中查看。这样,您可以有一个开始,停止和复位按钮的图像。单击后,图像可以链接到appscript中的函数,该函数在单个单元格中更新时间

下面是代码,下面是一个示例。请参阅“将操作附加到图像”文档,了解如何在需要时触发按钮

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');

function  countDownSeconds(seconds, minutes){
  while (minutes >=0){   
     sheet.getRange(2,1).setValue(minutes);     
    while (seconds >= 0 ){     
      var m = sheet.getRange(2,1).getValue()
      var s = sheet.getRange(2,2).getValue()
      if (m === 'pausing' || s === 'pausing'|| m === 'reset' || s === 'reset' ) {
       return
      }      
      sheet.getRange(2,2).setValue(seconds); 
      SpreadsheetApp.flush();
      Utilities.sleep(1000)
      seconds --
    }    
    seconds = 59;
    minutes = sheet.getRange(2,1).getValue();
    minutes --
  }
}

function startTimer(){
   var minutes = sheet.getRange(2,1).getValue()
   var seconds = sheet.getRange(2,2).getValue()
   countDownSeconds(seconds, minutes)

}

function pause(){
   var minutes = sheet.getRange(2,1).getValue()
   var seconds = sheet.getRange(2,2).getValue()
   sheet.getRange(2,1).setValue('pausing');  
   sheet.getRange(2,2).setValue('pausing');   
   SpreadsheetApp.flush();
   Utilities.sleep(1000);
   sheet.getRange(2,1).setValue(minutes)
   sheet.getRange(2,2).setValue(seconds)
}

function reset(){
   sheet.getRange(2,1).setValue('reset');  
   sheet.getRange(2,2).setValue('reset');   
   SpreadsheetApp.flush();
   Utilities.sleep(1000);
   sheet.getRange(2,1).setValue(0)
   sheet.getRange(2,2).setValue(0)
}
你可以在谷歌表格中找到。这样,您可以有一个开始,停止和复位按钮的图像。单击后,图像可以链接到appscript中的函数,该函数在单个单元格中更新时间

下面是代码,下面是一个示例。请参阅“将操作附加到图像”文档,了解如何在需要时触发按钮

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');

function  countDownSeconds(seconds, minutes){
  while (minutes >=0){   
     sheet.getRange(2,1).setValue(minutes);     
    while (seconds >= 0 ){     
      var m = sheet.getRange(2,1).getValue()
      var s = sheet.getRange(2,2).getValue()
      if (m === 'pausing' || s === 'pausing'|| m === 'reset' || s === 'reset' ) {
       return
      }      
      sheet.getRange(2,2).setValue(seconds); 
      SpreadsheetApp.flush();
      Utilities.sleep(1000)
      seconds --
    }    
    seconds = 59;
    minutes = sheet.getRange(2,1).getValue();
    minutes --
  }
}

function startTimer(){
   var minutes = sheet.getRange(2,1).getValue()
   var seconds = sheet.getRange(2,2).getValue()
   countDownSeconds(seconds, minutes)

}

function pause(){
   var minutes = sheet.getRange(2,1).getValue()
   var seconds = sheet.getRange(2,2).getValue()
   sheet.getRange(2,1).setValue('pausing');  
   sheet.getRange(2,2).setValue('pausing');   
   SpreadsheetApp.flush();
   Utilities.sleep(1000);
   sheet.getRange(2,1).setValue(minutes)
   sheet.getRange(2,2).setValue(seconds)
}

function reset(){
   sheet.getRange(2,1).setValue('reset');  
   sheet.getRange(2,2).setValue('reset');   
   SpreadsheetApp.flush();
   Utilities.sleep(1000);
   sheet.getRange(2,1).setValue(0)
   sheet.getRange(2,2).setValue(0)
}


你能在你的问题中加入更多的细节吗,比如你已经尝试了什么,你可能会收到什么错误信息?你越详细、越清楚,就越有可能有人能回答你的问题。事实上,我没有写脚本,我只是谷歌表单的开始用户。我的意思是我想创造这样的东西。在视频中使用excel VBA。请帮我解决这个问题。你能在你的问题中加入更多的细节吗,比如你已经尝试了什么,你可能会收到什么错误消息?你越详细、越清楚,就越有可能有人能回答你的问题。事实上,我没有写脚本,我只是谷歌表单的开始用户。我的意思是我想创造这样的东西。在视频中使用excel VBA。请帮我解决。谢谢你的解释。我有个小问题。如何在活动工作表中的指定范围内显示倒计时计时器。您可以将其放在侧栏或对话框上(最好是无模式)。是的,已经尝试过,但我想将其放在工作表中的特定范围内,而不是小部件或对话框中。。请帮帮我据我所知,这是不可能的。谢谢你的解释。我有个小问题。如何在活动工作表中的指定范围内显示倒计时计时器。您可以将其放在侧栏或对话框上(最好是无模式)。是的,已经尝试过,但我想将其放在工作表中的特定范围内,而不是小部件或对话框中。。请帮帮我据我所知,这是不可能的。谢谢你的建议。顺便说一句,我可以和我分享一下。我非常感谢你的帮助,但我有一个问题。如何在一个单元格中输入分钟和秒之间的时间。;-)嘿@Jason Allshorn,我带着同样的问题来到这里,并设法从您的答案中获得代码,所以谢谢您!我只有一个问题——至少在我的计算机上,您的代码和我的代码似乎都以低于1秒的速度执行计时器。你知道如何优化它吗?谢谢你的建议。顺便说一句,我可以和我分享一下。我非常感谢你的帮助,但我有一个问题。如何在一个单元格中输入分钟和秒之间的时间。;-)嘿@Jason Allshorn,我带着同样的问题来到这里,并设法从您的答案中获得代码,所以谢谢您!我只有一个问题——至少在我的计算机上,您的代码和我的代码似乎都以低于1秒的速度执行计时器。你知道如何优化它吗?