I'm writing a Google Apps Script on a Google Sheet. I want to set border on a range.
Here is my simple code that recorded by Macro feature in Google Sheet.
/** @OnlyCurrentDoc */
function _1() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A1:F10').activate();
spreadsheet.getActiveRangeList().setBorder(true, true, true, true, true, true, '#000000', SpreadsheetApp.BorderStyle.SOLID);
};
When I run it, it will show up the following error:
Error: The parameters (Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,String,number) don't match the method signature for SpreadsheetApp.RangeList.setBorder.
I checked the docs here: https://developers.google.com/apps-script/reference/spreadsheet/range-list#setbordertop,-left,-bottom,-right,-vertical,-horizontal,-color,-style
I think it should be right. I don't know why it's not working.
The issue is coming from the fact that ActiveRangeList
, is expecting a List of Ranges. However, the way you select range to be activated only produces a Range and will provide inconsistent results. by replicating your concern, and testing these proposed changes I was able to run it consistently.If there are scenario that you will have a list of range to run this code I suggest creating a Range checker if it the range provided or activated is just a Range or a Range List for a better result.
/** @OnlyCurrentDoc */
function _1() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A1:F10').activate();
spreadsheet.getActiveRange().setBorder(true, true, true, true, true, true, '#000000', SpreadsheetApp.BorderStyle.SOLID);
};