简体   繁体   English

仅限数字的 Google 表格自动备份

[英]Numbers only Google Sheets automated backup

I'm looking for a way to automatically backup a google sheets file without the functions, only the numbers.我正在寻找一种方法来自动备份没有功能的谷歌表格文件,只有数字。

I have scavenged 2 scripts from various sources:我从各种来源清除了 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);
}

The other is:另一个是:

function getRangeValues() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getRange("A2:B4");
  var values = range.getValues();
  return values;
};

Data from multiple sheets files are pulled into 1 master file, and I wanna have backups every week of every single one of them, but problem is with the 'makeCopy' function the data pulled into the copy of the master file will be coming from the original sheets, because i'm using the importrange function which requires unique sheets ID, and the copy has another ID.来自多个工作表文件的数据被提取到 1 个主文件中,我想每周对其中的每个文件进行备份,但问题在于“makeCopy”功能,将数据拉入主文件的副本将来自原始工作表,因为我正在使用需要唯一工作表 ID 的 importrange 函数,而副本具有另一个 ID。 How can I combine these 2 together?我怎样才能将这两个结合在一起?

Try this:尝试这个:

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

I think the problem was that we needed to authorize the import on the other sheet.我认为问题在于我们需要在另一张纸上授权导入。 Try it.尝试一下。 See if it works on your spreadsheet.看看它是否适用于您的电子表格。

function makeCopy() {
  var folder=DriveApp.getFolderById("Folder Id");
  var formattedDate = Utilities.formatDate(new Date(), "GMT", "yyyy.MM.dd");
  var ss=SpreadsheetApp.getActive();
  var fileName = formattedDate + " " + ss.getName();
  var file=DriveApp.getFileById(ss.getId());
  var f=file.makeCopy(fileName,folder);
  var copy=SpreadsheetApp.openById(file.getId());
  var shts=copy.getSheets();
  shts.forEach(function(sh){
    var rg=sh.getDataRange();
    var dvA=rg.getDisplayValues();
    sh.clearContents();
    rg.setValues(dvA);
  });
}

This is what I could blend together, and it erases references in the original file not the copied version.这是我可以混合在一起的,它会删除原始文件中的引用而不是复制版本。 I'm sure this is the way, just need a little tweaking here and there.我确定这就是方法,只需要在这里和那里进行一些调整。

Can you give me some hints how to do that?你能给我一些提示如何做到这一点吗?

THANKS FOR YOUR HELP!!!!感谢您的帮助!!!!

You need to change你需要改变
var copy=SpreadsheetApp.openById(file.getId()); to var copy=SpreadsheetApp.openById(f.getId());var copy=SpreadsheetApp.openById(f.getId());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM