War*_*ton 5 google-sheets google-apps-script google-sheets-api google-sheets-vlookup
我想将包含 20 多张工作表的整个电子表格复制到云端硬盘中的其他位置;但是,我只想保留每个单元格中的硬值和格式,而不是公式(基本上只是拍摄值的快照)。我一直在考虑如何写这个,但我不知道什么是最好的方法。我刚刚开始学习条件语句,例如在我的谷歌表格培训中循环,任何帮助将不胜感激。谢谢!
那些绿色的单元格都是 vlookup,它们是从另一个电子表格上的数组更新的。我们的想法是获取数组中的所有正确数据,让这张表完全填写当天的正确值,然后最好将其保存为谷歌表,但只保存值,以便事后可以编辑它们(如果有)数组数据中有错误。
a date stamped on it for a name文件名。many vlookups and other outside reference cells在您的电子表格中,包含的公式。如果我的理解是正确的,这个答案怎么样?请将此视为几个可能答案之一。
实现上述目标的示例脚本的流程如下。
在运行脚本之前,请设置源电子表格 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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3725 次 |
| 最近记录: |