谷歌Apps脚本不能出口任何东西比PDF原生,但该文件API并因此您可以使用网址提取与参数,以获得你想要的(不改变这些参数,请求是匿名的并且可以保留)。
下面是代码,它不需要除了网址提取必须经过授权过多的解释(这个过程是不是一般的一个,你会得到第二次授权此脚本。)
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"};
}
Thanx Serge。它可以工作,但是我喜欢根据Google Spreadsheet中的电子邮件地址发送电子邮件。当我这样做是行不通的(目标用户没有收到邮件)。任何想法? –
我认为出了什么问题......它似乎很好地工作,谢谢。 –
很高兴听到它,谢谢 –