电子表格在哪里有数据

时间:2017-10-30 11:05:46

标签: google-app-maker

是否可以访问谷歌驱动器表格,因为它包含应用程序制造商模型的数据?我的意思是 - 是否可以将其作为电子表格打开?

由于 雷

1 个答案:

答案 0 :(得分:0)

是。您可以使用电子表格作为数据源。我用一个简单的电子表格来收集3个项目。我正在玩电子邮件发件人教程,我想收集一份我已发送的电子邮件列表。我创建了字段并进入了数据源选项卡,并将此代码添加到queryRecords()函数中。

var ss=SpreadsheetApp.openById('id');
var sh=ss.getSheetByName('RecentEmails');
var rg=sh.getRange(2,1,sh.getLastRow(),sh.getLastColumn());
var vA=rg.getValues();
var reRecords=[];
for(var i=0;i<vA.length;i++){
  var reRecord=app.models.RecentEmails.newRecord();
  reRecord.Recipient=vA[i][0];
  reRecord.Date=vA[i][1].toString();
  reRecord.Message=vA[i][2];
  reRecords.push(reRecord);
}
return reRecords;

上述函数加载数据源。

然后我将一个表连接到数据源,每当加载页面时数据都会更新。

我使用如下函数将数据加载到表中:

function archiveSentEmails(to,when,what)
{
  var ss=SpreadsheetApp.openById('id');
  var sh=ss.getSheetByName('RecentEmails');
  sh.appendRow([to,when,what]);
}

它放在MailApp.sendMail函数所在的服务器端脚本中。

按下“发送电子邮件”按钮时,它会调用此客户端函数,该函数通过google.script.run调用服务器端函数。

function sendMessage(to, subject, msg){
  var status = app.pages.Email.descendants.EmailStatus;
  google.script.run
   .withFailureHandler(function(error) {
      // An error occurred, so display an error message.
      status.text = error.message;
    })
  .withSuccessHandler(function(result) {
     // Report that the email was sent.
    status.text = 'Email sent...';
    clearEmailForm();
    loadDebugElements();
    app.datasources.RecentEmails.load();//this lines refreshes the widgets attached to the datasource

   })
 .sendEmailMessage(to, subject, msg);
}

然后我将命令app.datasources.RecentEmails.load放在withSuccessHandler中,以便每次发送电子邮件时最近的电子邮件表都会更新,这样您就不必在每封电子邮件后都有一个按钮来启动更新表发送。

相关问题