google-apps-script - 仅限数字 Google 表格自动备份
问题描述
我正在寻找一种方法来自动备份没有功能的谷歌表格文件,只有数字。
我从各种来源清除了 2 个脚本:
// Abhijeet Chopra
// 26 February 2016
// Google Apps Script to make copies of Google Sheet in specified destination folder
function makeCopy() {
// generates the timestamp and stores in variable formattedDate as year-month-date hour-minute-second
var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd' 'HH:mm:ss");
// gets the name of the original file and appends the word "copy" followed by the timestamp stored in formattedDate
var name = SpreadsheetApp.getActiveSpreadsheet().getName() + " Copy " + formattedDate;
// gets the destination folder by their ID. REPLACE xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx with your folder's ID that you can get by opening the folder in Google Drive and checking the URL in the browser's address bar
var destination = DriveApp.getFolderById("1ysgERhjmrnq5Uzb9Lu7CtqOWccVTHyVj");
// gets the current Google Sheet file
var file = DriveApp.getFileById(SpreadsheetApp.getActiveSpreadsheet().getId())
// makes copy of "file" with "name" at the "destination"
file.makeCopy(name, destination);
}
另一个是:
function getRangeValues() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A2:B4");
var values = range.getValues();
return values;
};
来自多个工作表文件的数据被拉入 1 个主文件,我想每周对其中的每一个文件进行备份,但问题在于“makeCopy”功能,拉入主文件副本的数据将来自原始工作表,因为我正在使用需要唯一工作表 ID 的 importrange 功能,而副本有另一个 ID。我怎样才能将这两个结合在一起?
解决方案
试试这个:
function makeCopy() {
var folder=DriveApp.getFolderById("1y66aE2WuaRQQM5fyevXEl5uhJamk9VF7");
var ss=SpreadsheetApp.getActive();
var file=DriveApp.getFileById(ss.getId());
var f=file.makeCopy(folder);
var copy=SpreadsheetApp.openById(f.getId());
var shts=copy.getSheets();
SpreadsheetApp.getUi().alert('Go to other sheet to authorize Import. Hit Okay after authorizing the Import');
shts.forEach(function(sh){
var rg=sh.getDataRange();
var dvA=rg.getValues();
sh.clearContents();
rg.setValues(dvA);
});
}
我认为问题在于我们需要在另一张纸上授权导入。尝试一下。看看它是否适用于您的电子表格。
推荐阅读
- python - 将悬停文本添加到 Plotly 散点图线或散点图线的多种颜色
- javascript - 返回或推送字符串 Char
- export - Sqoop 导出失败并出现 NumberFormatException
- excel - 如何将多个句子中的每个单词放入Excel中的文本单元格?
- .net-core - .NET 核心中的 OpenTracing,而不依赖于特定的解决方案库
- powershell - 如何从结果对象 Invoke-WebRequest 命令中“单击”元素
- python - Selenium Webdriver with Python - 无法在使用 Selenium Web 驱动程序的 Web 应用程序中提供输入
- oracle-apex-5.1 - 从 CSV 文件加载 Apex 数据 - 表查找问题
- sql - 如何添加 CTE 以提高存储过程性能?
- mysql - 如何处理nodejs中的mysql错误?如果结果是一个空数组?