我在 Sheets 中录制了一个宏,其目的是添加带有条件格式的色标。它工作得很好,但是当它完成时我得到两个弹出窗口说“完成”。我已经将这些追溯到我过去使用过的另外两个应用程序脚本。(注意:这些是脚本,不是录制的宏)
问:为什么,当我使用分配的键盘快捷键调用宏时,我还会看到其他脚本的弹出窗口?脚本本身似乎没有完全运行(因为它们修改的范围没有改变)。
这是录制的宏:
function Addcolourscale() {
var spreadsheet = SpreadsheetApp.getActive();
var conditionalFormatRules = spreadsheet.getActiveSheet().getConditionalFormatRules();
conditionalFormatRules.push(SpreadsheetApp.newConditionalFormatRule()
.setRanges([spreadsheet.getActiveRange()])
.whenCellNotEmpty()
.setBackground('#B7E1CD')
.build());
spreadsheet.getActiveSheet().setConditionalFormatRules(conditionalFormatRules);
conditionalFormatRules = spreadsheet.getActiveSheet().getConditionalFormatRules();
conditionalFormatRules.splice(conditionalFormatRules.length - 1, 1, SpreadsheetApp.newConditionalFormatRule()
.setRanges([spreadsheet.getActiveRange()])
.setGradientMinpoint('#57BB8A')
.setGradientMaxpoint('#FFFFFF')
.build());
spreadsheet.getActiveSheet().setConditionalFormatRules(conditionalFormatRules);
conditionalFormatRules = spreadsheet.getActiveSheet().getConditionalFormatRules();
conditionalFormatRules.splice(conditionalFormatRules.length - 1, 1, SpreadsheetApp.newConditionalFormatRule()
.setRanges([spreadsheet.getActiveRange()])
.setGradientMinpoint('#57BB8A')
.setGradientMidpointWithValue('#FFD666', SpreadsheetApp.InterpolationType.PERCENTILE, '50')
.setGradientMaxpoint('#E67C73')
.build());
spreadsheet.getActiveSheet().setConditionalFormatRules(conditionalFormatRules);
};
这是在上述宏完成时产生弹出窗口的脚本之一,因为它的最后两行。这是我从网上资源改编的,所以不太了解。
function CopyClientChannelUseBack(){
/* Edit the vars below this line for your needs */
var sourceSheet = "12 mth Client channel use" ; // Enter the name of the sheet with the source data
var sourceRange = "A19:S29" ; // Enter the range of the cells with the source data
var targetSheet = "12 mth Client channel use" ; // Enter the name of the target sheet
var targetRange = "A20:S30" ; // Enter the range of cells you wish to copy data to. Note this must be same size as source range.
/* No need to edit below this point */
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sourceSheet);
var values = sheet.getRange(sourceRange).getValues();
ss.getSheetByName(targetSheet).getRange(targetRange).setValues(values);
SpreadsheetApp.flush()
/* Edit the vars below this line for your needs */
var sourceSheet = "12 mth Client channel use" ; // Enter the name of the sheet with the source data
var sourceRange = "A49:N59" ; // Enter the range of the cells with the source data
var targetSheet = "12 mth Client channel use" ; // Enter the name of the target sheet
var targetRange = "A50:N60" ; // Enter the range of cells you wish to copy data to. Note this must be same size as source range.
/* No need to edit below this point */
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(sourceSheet);
var values = sheet.getRange(sourceRange).getValues();
ss.getSheetByName(targetSheet).getRange(targetRange).setValues(values);
SpreadsheetApp.flush()
SpreadsheetApp.getUi().alert("Done")
}
清单文件没有引用脚本,只有宏。
{
"timeZone": "Europe/London",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"sheets": {
"macros": [{
"menuName": "Add colour scale",
"functionName": "Addcolourscale",
"defaultShortcut": "Ctrl+Alt+Shift+9"
}]
}
}