当特定单元格更改值 google 表时播放声音

Play Sound when a specific cell change the Value google sheets

我正在尝试 运行 这个 post 的代码,:

根据 Rob Blakemore 的推荐

有人可以给我一个可以使用此代码的 sheet 吗?

我已尝试在 sheet 中测试此代码,但它对我不起作用。

它只向我发送消息:正在检查呼叫...

我把我的 sheet 的 link 发给你:

https://docs.google.com/spreadsheets/d/1rdm0zmZMherO8IspDb3Ce9n0j9tLYFYtM9V8fIX8uV4/edit#gid=0

这是appscript的代码:

Code:
// creates a custom menu when the spreadsheet is opened
function onOpen() {
  var ui = SpreadsheetApp.getUi()
    .createMenu('Call App')
    .addItem('Open Call Notifier', 'openCallNotifier')
    .addToUi();

  // you could also open the call notifier sidebar when the spreadsheet opens
  // if you find that more convenient
  // openCallNotifier();
}

// opens the sidebar app
function openCallNotifier() {
  // get the html from the file called "Page.html"
  var html = HtmlService.createHtmlOutputFromFile('Page') 
    .setTitle("Call Notifier");

  // open the sidebar
  SpreadsheetApp.getUi()
    .showSidebar(html);
}

// returns a list of values in column H
function getColumnH() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Support");

  // get the values in column H and turn the rows into a single values
  return sheet.getRange(1, 8, sheet.getLastRow(), 1).getValues().map(function (row) { return row[0]; });

页数:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <p id="message">Checking for calls...</p>

    <audio id="call">
      <!-- <source src="http://docs.google.com/uc?export=open&id=1CfWaMX6wfJSSdp-u_rU0bkRpwNmXWpVu/view?usp=sharing" type="audio/mp3"> -->

<source src="http://docs.google.com/uc?export=open&id=1CfWaMX6wfJSSdp-u_rU0bkRpwNmXWpVu/view?usp=sharing" type="audio/mp3">


      Your browser does not support the audio element.
    </audio>

    <script>
    var lastTime = []; // store the last result to track changes

    function checkCalls() {

      // This calls the "getColumnH" function on the server
      // Then it waits for the results
      // When it gets the results back from the server,
      // it calls the callback function passed into withSuccessHandler
      google.script.run.withSuccessHandler(function (columnH) {
        for (var i = 0; i < columnH.length; i++) {

          // if there's a difference and it's a call, notify the user
          if (lastTime[i] !== columnH[i] && columnH[i] === "Call") {
            notify();
          }
        }

        // store results for next time
        lastTime = columnH;

        console.log(lastTime);

        // poll again in x miliseconds
        var x = 1000; // 1 second
        //window.setTimeout(checkCalls, x);
      }).getColumnH();
    }

    function notify() {
      document.getElementById("call").play();
    }

    window.onload = function () {
      checkCalls();
    }

    function timer(ms) {
   return new Promise(res => setTimeout(res, ms));
  }

  
  async function loopthis () { // We need to wrap the loop into an async function for the await call (to the Promise) to work.  [From web: "An async function is a function declared with the async keyword. Async functions are instances of the AsyncFunction constructor, and the await keyword is permitted within them. The async and await keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly configure promise chains."]
    for (var i = 0; i >= 0; i++) {
      console.log('Number of times function has been run: ' + i);
      checkCalls();
      await timer(3000);
    }
  }


  window.onload = function () {
    loopthis();
  }

    </script>
  </body>
</html>

在你的脚本中,如何改变 mp3 文件的端点如下?

发件人:

<source src="http://docs.google.com/uc?export=open&id=1CfWaMX6wfJSSdp-u_rU0bkRpwNmXWpVu/view?usp=sharing" type="audio/mp3">

收件人:

<source src="https://drive.google.com/uc?id=1CfWaMX6wfJSSdp-u_rU0bkRpwNmXWpVu&export=download" type="audio/mp3">
  • 在这种情况下,使用webContentLink

注:

  • 当我通过反映此修改来测试您的脚本时,我确认您的 mp3 文件已播放。