gpt4 book ai didi

google-apps-script - Google Apps脚本可通过电子邮件发送Google电子表格Excel版本

转载 作者:行者123 更新时间:2023-12-01 08:22:50 25 4
gpt4 key购买 nike

我想编写一个应用脚本来通过电子邮件发送我的Google Spreadsheet的excel版本。我知道我可以将电子表格另存为Excel文件。我不确定是否可以使用脚本通过电子邮件将excel版本作为附件发送出去。如何才能做到这一点?

最佳答案

answer on another recent post(Thomas van Latum)之后,我尝试了建议的doc api并得到了一个有趣的结果...这是我使用的测试代码,除了文件为xlsx格式(不是xls格式)外,它工作得很好,但这不一定是这些天发行:

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"};
}

function test(){
var id = 'spreadsheet_ID'
var url = 'https://docs.google.com/feeds/';
var doc = UrlFetchApp.fetch(url+'download/spreadsheets/Export?key='+id+'&exportFormat=xls',
googleOAuth_('docs',url)).getBlob()
DocsList.createFile(doc).rename('newfile.xls')
}

注意:如果不重命名,其默认名称为 Export.xlsx,获取其ID以便以后使用可能会更有用...
所以最后一行可能是这样的:
var xlsfileID = DocsList.createFile(doc).getId()

编辑:触发授权过程,尝试一个小的功能,从脚本编辑器运行它
function autorise(){
// function to call to authorize googleOauth
var id=SpreadsheetApp.getActiveSpreadsheet().getId();
var url = 'https://docs.google.com/feeds/';
var doc = UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=html&format=html&id='+id,
googleOAuth_('docs',url)).getContentText();
}

关于google-apps-script - Google Apps脚本可通过电子邮件发送Google电子表格Excel版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12712137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com