It is possible to set the range border style and color. Now the question is: how can we get the border style programmatically?
I'm looking for something like:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var b2 = sheet.getRange("B2");
var border = b2.getBorder(); // getBorder does not exist, but b2.setBorder does :-/
I'm not sure whether this is the best way. I always retrieve the border style using Sheets API. The sample script is as follows.
When you use this sample script, please enable Sheets API.
From April 8, 2019, the specification for enabling API has been changed for the GAS project created after April 8, 2019. Ref
In this case, when the API is enabled at Advanced Google services, the API is automatically enabled at API console. So you can use the API by only enabling it at Advanced Google services.
Enable Sheets API v4 at Advanced Google ServicesIn this case, the API is required to be enabled at Advanced Google services and API console.
Enable Sheets API v4 at Advanced Google ServicesIf now you are opening the script editor with the script for using Sheets API, you can enable Sheets API for the project by accessing this URL https://console.cloud.google.com/apis/library/sheets.googleapis.com/
If you want to use the API which is not included in the Advanced Google services at GAS project created after April 8, 2019, it is required to link Cloud Platform Project to Google Apps Script Project. And the API is required to be enabled at API console. You can see the detail flow of this at here.
var spreadsheetId = SpreadsheetApp.getActiveSpreadsheet().getId();
var res = Sheets.Spreadsheets.get(spreadsheetId, {ranges: "Sheet1!B2", fields: "sheets/data/rowData/values/userEnteredFormat/borders"});
If this was not useful for you, I'm sorry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With