我正在设置电子表格,我需要保护副本中的单元格。由于复制新表格时Google表格不会复制保护,因此我遇到了此代码。这是一个撤消功能,但仅适用于文本,不适用于公式。关于如何更改它的任何想法?
我已将.getValue
更改为.getFormula
,但是没有运气。
var masterSheetName = "Master" // sheet where the cells are protected from updates
var helperSheetName = "Backup" // sheet where the values are copied for later checking
var ss = SpreadsheetApp.getActiveSpreadsheet();
var masterSheet = ss.getActiveSheet();
if (masterSheet.getName() != masterSheetName) return;
var masterRange = masterSheet.getActiveRange();
var helperSheet = ss.getSheetByName(helperSheetName);
var helperRange = helperSheet.getRange(masterRange.getA1Notation());
var newValue = masterRange.getValues();
var oldValue = helperRange.getValues();
Logger.log("newValue " + newValue);
Logger.log("oldValue " + oldValue);
Logger.log(typeof(oldValue));
if (oldValue == "" || isEmptyArrays(oldValue)) {
helperRange.setValues(newValue);
} else {
Logger.log(oldValue);
masterRange.setValues(oldValue);
}
}