How do I script making a backup copy of a spreadsheet and its values not its formulas to an archive folder?

为君一笑 提交于 2019-12-23 04:55:25

问题


I am new to google app scripts and I have been looking for a way to back up a sheet. I am currently using.

DriveApp.getFileById("146qFnrQoNPBcDhV6QB0bscHFp8TquXJoAC1qg‌​_esy4E").makeCopy("D‌​ailyArchive" + Date() + " backup");

The problem is its making a daily backup and those backups are updating just like the original and I just want to make a backup of the values so I have a archive. In my sheet I am importing data from a jail roster. http://www.kitsapgov.com/sheriff/incustody/jailwebname.xml


回答1:


Here something quite simple for one sheet (you can adapt it for several sheets)

  var source = SpreadsheetApp.getActiveSpreadsheet();
  var data = source.getActiveSheet().getDataRange();
  var cible = SpreadsheetApp.create(source.getName()+" backup");
  cible.getActiveSheet().getRange(data.getA1Notation()).setValues(data.getValues());
  Logger.log(cible.getId());
  Logger.log(cible.getUrl());


来源:https://stackoverflow.com/questions/39283110/how-do-i-script-making-a-backup-copy-of-a-spreadsheet-and-its-values-not-its-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!