将整个Google Sheets作为附件发到指定邮箱进行备份

脚本加上Google Scripts的定时执行,可以做到每隔一定时间将整个Google Sheets作为附件发到指定邮箱备份。

//////////////

function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {name: “Send Email”, functionName: “backupGoogleSpreadsheetAsExcel”}];
ss.addMenu(“Scripts”, menuEntries);
};

function backupGoogleSpreadsheetAsExcel(){

try {

var ss = SpreadsheetApp.getActive();

var url = “https://docs.google.com/feeds/download/spreadsheets/Export?key=” + ss.getId() + “&exportFormat=xlsx”;

var params = {
method : “get”,
headers : {“Authorization”: “Bearer ” + ScriptApp.getOAuthToken()},
muteHttpExceptions: true
};

var blob = UrlFetchApp.fetch(url, params).getBlob();

blob.setName(ss.getName() + “.xlsx”);

MailApp.sendEmail(“收邮箱”, “Google Sheet to Excel”, “The XLSX file is attached”, {attachments: [blob]});

} catch (f) {
Logger.log(f.toString());
}
}

///////////////

转自:https://www.hostloc.com/thread-541812-1-1.html

未经允许不得转载:LowVPS » 将整个Google Sheets作为附件发到指定邮箱进行备份

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址