【发布时间】:2021-06-15 05:26:41
【问题描述】:
我是脚本的新手。我有一个脚本(pasteValues)
- 查看活动电子表格
- 粘贴值,使所有公式变为静态值。
- 将超链接公式插入特定的命名单元格(本例中为 L3)。
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var pasteValues = [ {name: "Paste Values", functionName: "pasteValues"}];
ss.addMenu("Paste Values", pasteValues);
}
function pasteValues() {
var spreadsheet = SpreadsheetApp.getActive();
var currentCell = spreadsheet.getCurrentCell();
spreadsheet.getActiveRange().getDataRegion().activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
var sheet = spreadsheet.getActiveSheet();
sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()).activate();
currentCell.activateAsCurrentCell();
sheet = spreadsheet.getActiveSheet();
sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()).copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
var cell = sheet.getRange("L3");
cell.setFormula('=HYPERLINK("https://docs.google.com/spreadsheets/d/11wN66ClYQf4soG6UnlWrqBz5hSMSj0c8ceI_0Zt-s7o/","Link to Master Schedule")')
}
;
我目前已经在 100 多个不同的电子表格上安装了此脚本,并使用菜单选项来运行脚本(我打开每个电子表格并通过“onOpen”脚本中生成的菜单选项卡运行脚本)。
我想做的就是能够
- 打开我的主表(称为“示例计划”)
- 在与“Sample Schedule”位于同一文件夹中的所有工作表中运行 pastevalues 函数脚本(最好通过菜单选项卡访问)
- 但 pastevalues 函数只能用于特定命名的工作表。 (即,每张工作表都有 10 个或更多选项卡,名为“Summer 2021”的选项卡是我想在其上使用 pastevalues 功能的选项卡。此选项卡名称在文件夹中的所有工作表中都是一致的。
我目前有一个脚本(安装在“示例计划”上,我已经使用了一段时间,它将示例计划的活动选项卡复制到文件夹中的所有工作表。这是目前正在努力实现的目标:
function copySheet() {
var source = SpreadsheetApp.getActiveSpreadsheet();
var sheet = source.getSheets()[0];
var sourceFile = DriveApp.getFileById(source.getId());
var sourceFolder = sourceFile.getParents().next();
var folderFiles = sourceFolder.getFiles();
var thisFile;
while (folderFiles.hasNext()) {
thisFile = folderFiles.next();
if (thisFile.getName() !== sourceFile.getName()){
var currentSS = SpreadsheetApp.openById(thisFile.getId());
sheet.copyTo(currentSS);
currentSS.getSheets()[currentSS.getSheets().length-1].setName('Summer 2021').activate();
currentSS.moveActiveSheet(1);
}
};
}
但我未能将此脚本改编为我的新“PasteValues”脚本。
我在 Stack Overflow 上查看了很多关于如何在同一个文件夹中跨多个工作表运行函数的答案,但我无法做到(我只是设法制作粘贴值(粘贴值+ 特定单元格工作中的超链接)。几个月来,我一直在努力实现这一目标,而我有空闲时间,但如果有人能帮助我,那就太好了。
【问题讨论】:
标签: google-apps-script google-sheets