Google apps script 如何将随机选择的欢迎文本从google工作表列显示到web应用程序索引页?

Google apps script 如何将随机选择的欢迎文本从google工作表列显示到web应用程序索引页?,google-apps-script,Google Apps Script,我想向用户显示从Sheet1列A1:a(最后一列有文本)中随机选择的文本。我可以用谷歌和 和分配给“显示”按钮的脚本代码: 函数random1(){ var ss=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet() var val=ss.getRange(“B1”).getValue() var clr=ss.getRange(“C1”).clearContent() ss.getRange(“C1”).setValue(val) }

我想向用户显示从Sheet1列A1:a(最后一列有文本)中随机选择的文本。我可以用谷歌和

和分配给“显示”按钮的脚本代码:

函数random1(){
var ss=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
var val=ss.getRange(“B1”).getValue()
var clr=ss.getRange(“C1”).clearContent()
ss.getRange(“C1”).setValue(val)
}
试试这个:

G.gs:

function getThought() {
  var thoughtsA=SpreadsheetApp.getActive().getSheetByName("Thoughts").getDataRange().getValues();
  var index=Math.floor(Math.random()*(thoughtsA.length));
  return thoughtsA[index][0];
}

function launchThoughts() {
  var userInterface=HtmlService.createHtmlOutputFromFile('thoughts');
  SpreadsheetApp.getUi().showModelessDialog(userInterface, "This Mornings Thought");
}
Thinks.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
    $(function(){
      google.script.run
      .withSuccessHandler(function(thought) {
        $('#thought').html(thought);
      })
      .getThought();
    });
    </script>
  <style>#thought {font-size:60px;color:blue;}</style>
  </head>
  <body>
    <div id="thought"></div>
  </body>
</html>

$(函数(){
google.script.run
.withSuccessHandler(函数(思想){
$('#think').html(think);
})
.getthough();
});
#思想{字体大小:60px;颜色:蓝色;}
我的电子表格有一张叫做“想法”的表格。看起来是这样的:


我想你可以添加这些想法。

对不起!我得到“未找到脚本函数:doGet”!!对因为我是作为对话来做的。查看thinks.gs中的
launchthinks()
。更改为对话框很容易,但作为对话框调试更容易,因此,让它准确工作,然后将其转换为webapp。
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
    $(function(){
      google.script.run
      .withSuccessHandler(function(thought) {
        $('#thought').html(thought);
      })
      .getThought();
    });
    </script>
  <style>#thought {font-size:60px;color:blue;}</style>
  </head>
  <body>
    <div id="thought"></div>
  </body>
</html>