Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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脚本将附件作为Word文档发送_Google Apps Script - Fatal编程技术网

Google apps script 通过Google脚本将附件作为Word文档发送

Google apps script 通过Google脚本将附件作为Word文档发送,google-apps-script,Google Apps Script,通过谷歌电子表格,我想发送一个附件。附件是一个谷歌文档 我可以将它作为PDF file.getAs('application/PDF')发送——但是我需要它作为Word文档(或者在Word中打开的东西)发送 可以通过Word附件手动发送电子邮件,但此解决方案需要自动发送 我尝试了:application/vnd.openxmlformats-officedocument.wordprocessingml.document(),但没有成功 问候 StefanGoogle Apps脚本无法以本机方式

通过谷歌电子表格,我想发送一个附件。附件是一个谷歌文档

我可以将它作为PDF file.getAs('application/PDF')发送——但是我需要它作为Word文档(或者在Word中打开的东西)发送

可以通过Word附件手动发送电子邮件,但此解决方案需要自动发送

我尝试了:application/vnd.openxmlformats-officedocument.wordprocessingml.document(),但没有成功

问候


Stefan

Google Apps脚本无法以本机方式导出pdf以外的任何内容,但文档API可以这样做,因此您可以使用带有参数的urlFetch来获取所需内容(不要更改这些参数,请求是匿名的,可以保持匿名)

下面是代码,它不需要太多解释,只需要对urlFetch进行授权(该过程不是通常的过程,您将获得该脚本的第二次授权)


桑克斯哔叽。它的工作,但我喜欢有电子邮件发送的基础上,在谷歌电子表格的电子邮件地址。当我这样做的时候,它不起作用(目标用户没有收到电子邮件)。有什么想法吗?我想是做错了什么…它似乎工作得很好,谢谢。Serge,我今天试过这个代码。直到昨天我还以为它运行得很顺利,但现在它不会运行了。我在var doc行之前和之后放了一个日志,之后的日志记录器没有显示在日志中。你知道发生了什么,更重要的是如何解决吗?处决记录上说了什么?
function emailDocTestasDocx() {
  var id = '1I9KIVTLieQbNnmz09zfOBSBNwZ9Tp7B0kfpysaf-ooY';// an example of Google doc
  var url = 'https://docs.google.com/feeds/';
  var doc = UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=doc&format=doc&id='+id,
                              googleOAuth_('docs',url)).getBlob();
  var me = Session.getEffectiveUser().getEmail();
  MailApp.sendEmail(me, 'test', 'see attachment', {attachments:[doc]});
}

function googleOAuth_(name,scope) {
  var oAuthConfig = UrlFetchApp.addOAuthService(name);
  oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
  oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oAuthConfig.setConsumerKey('anonymous');
  oAuthConfig.setConsumerSecret('anonymous');
  return {oAuthServiceName:name, oAuthUseToken:"always"};
}