[英]Copy an entire Spreadsheet, Just Preserve the Values
I want to copy an entire spreadsheet of some 20+ sheets to a different location in Drive;我想将包含 20 多张工作表的整个电子表格复制到云端硬盘中的其他位置; however, I only want to preserve the hard values and formatting in each cell, and not the formulas (basically just taking a snapshot of the values).
但是,我只想保留每个单元格中的硬值和格式,而不是公式(基本上只是对值进行快照)。 I have been playing around with how to write this but I don't have a solid idea on what's the best approach.
我一直在研究如何写这个,但我对什么是最好的方法没有一个可靠的想法。 I'm just starting to learn conditionals like looping in my google sheets training, any help would be appreciated.
我刚刚开始在我的谷歌表格培训中学习循环等条件,任何帮助将不胜感激。 Thanks!
谢谢!
Those cells in green are all vlookups and they update from an array I have on another spreadsheet.那些绿色的单元格都是 vlookup,它们从我在另一个电子表格上的数组中更新。 The idea is to get all the right data in the array, have this sheet fully fill out with the correct values for the day, then save it preferably as a google sheet but just the values, so that they are editable after the fact if there was an error in the array data.
这个想法是在数组中获取所有正确的数据,让这张表完全填写当天的正确值,然后最好将其保存为谷歌表,但只保存值,以便在事后可以编辑它们是数组数据中的错误。
a date stamped on it for a name
as the filename.a date stamped on it for a name
用作文件名。many vlookups and other outside reference cells
are included.many vlookups and other outside reference cells
的公式。 If my understanding is correct, how about this answer?如果我的理解是正确的,这个答案怎么样? Please think of this as just one of several possible answers.
请认为这只是几个可能的答案之一。
The flow of the sample script for the above goal is as follows.上述目标的示例脚本流程如下。
Before you run the script, please set the source Spreadsheet ID and the destination folder ID.在运行脚本之前,请设置源电子表格 ID 和目标文件夹 ID。
function myFunction() {
var spreadsheetId = "###"; // Please set the source Spreadsheet ID.
var destFolderId = "###"; // Please set the destination folder ID.
// Copy each sheet in the source Spreadsheet by removing the formulas as the temporal sheets.
var ss = SpreadsheetApp.openById(spreadsheetId);
var tempSheets = ss.getSheets().map(function(sheet) {
var dstSheet = sheet.copyTo(ss).setName(sheet.getSheetName() + "_temp");
var src = dstSheet.getDataRange();
src.copyTo(src, {contentsOnly: true});
return dstSheet;
});
// Copy the source Spreadsheet.
var destination = ss.copy(ss.getName() + " - " + new Date().toLocaleString());
// Delete the temporal sheets in the source Spreadsheet.
tempSheets.forEach(function(sheet) {ss.deleteSheet(sheet)});
// Delete the original sheets from the copied Spreadsheet and rename the copied sheets.
destination.getSheets().forEach(function(sheet) {
var sheetName = sheet.getSheetName();
if (sheetName.indexOf("_temp") == -1) {
destination.deleteSheet(sheet);
} else {
sheet.setName(sheetName.slice(0, -5));
}
});
// Move file to the destination folder.
var file = DriveApp.getFileById(destination.getId());
DriveApp.getFolderById(destFolderId).addFile(file);
file.getParents().next().removeFile(file);
}
If you actually plan on using this data you probably want to think twice of just randomly copying everything.如果你真的打算使用这些数据,你可能要三思而后行,只是随机复制所有内容。 If you want to just archive Just add
export?format=zip
to the end of your link, then you will have a saved copy with values and formatting.如果您只想存档只需将
export?format=zip
添加到链接的末尾,您将获得一个包含值和格式的保存副本。
Another very simple way is to Download the sheet to Excel.另一种非常简单的方法是将工作表下载到 Excel。 It will keep local formulas but remove external references (like importrange, etc), so data will stay frozen;) You can even open the Excel file from Gsheets (without converting it to sheets).
它将保留本地公式但删除外部引用(如 importrange 等),因此数据将保持冻结状态;)您甚至可以从 Gsheets 打开 Excel 文件(无需将其转换为工作表)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.