全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 697|回复: 2

自动邮件备份Google Sheets

[复制链接]
发表于 2019-4-23 14:15:58 | 显示全部楼层 |阅读模式
考虑最坏情况(Google账号被封),可能不是刚需。

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

  1. //////////////

  2. function onOpen() {
  3.   var ss = SpreadsheetApp.getActiveSpreadsheet();
  4.   var menuEntries = [ {name: "Send Email", functionName: "backupGoogleSpreadsheetAsExcel"}];
  5.   ss.addMenu("Scripts", menuEntries);
  6. };


  7. function backupGoogleSpreadsheetAsExcel(){
  8.   
  9.   try {
  10.    
  11.     var ss = SpreadsheetApp.getActive();
  12.    
  13.     var url = "https://docs.google.com/feeds/download/spreadsheets/Export?key=" + ss.getId() + "&exportFormat=xlsx";
  14.    
  15.     var params = {
  16.       method      : "get",
  17.       headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
  18.       muteHttpExceptions: true
  19.     };
  20.    
  21.     var blob = UrlFetchApp.fetch(url, params).getBlob();
  22.    
  23.     blob.setName(ss.getName() + ".xlsx");
  24.    
  25.     MailApp.sendEmail("收邮箱", "Google Sheet to Excel", "The XLSX file is attached", {attachments: [blob]});
  26.    
  27.   } catch (f) {
  28.     Logger.log(f.toString());
  29.   }
  30. }


  31. ///////////////
复制代码
发表于 2019-4-23 14:32:45 | 显示全部楼层
本帖最后由 UOvZ 于 2019-4-23 14:35 编辑

邮件备份最好不要备份大文件,总是会断的。


https://www.openos.org/post/287/
这个不错,可以试试。
 楼主| 发表于 2019-4-23 18:32:12 | 显示全部楼层
UOvZ 发表于 2019-4-23 14:32
邮件备份最好不要备份大文件,总是会断的。

大佬好文,要备份的只是几十KB的Google Sheets呢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-26 05:39 , Processed in 0.062670 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表