1

Follow up to this question using Google Apps Script: Set border color & style in spreadsheet programmatically

The format is in this order: .setBorder( top, left, bottom, right, vertical, horizontal, color, style )

According to the documentation,
"true" turns on format
"false" turns off format
"null" leaves it unchanged

My problem: "null" is turning the format off!

I have a very simple script for testing purposes:

var right = "red";  
var left = "blue";  
range.setBorder( null, null, null, true, null, null, right, null );  
range.setBorder( null, true, null, null, null, null, left, null );  

Shouldn't this set the right border red and the left border blue?
The result is only the blue. If I omit the blue line, it'll result in the red.
It seems the only way to get 2+ colors in a single cell is to do .setBorder separately using "null". But "null" is working as "false" and turning off the previous border.

Community
  • 1
  • 1
Laila B
  • 13
  • 2

2 Answers2

1

SpreadsheetApp.flush() should solve the problem:

range.setBorder( null, null, null, true, null, null, right, null );
SpreadsheetApp.flush();
range.setBorder( null, true, null, null, null, null, left, null );  
utphx
  • 1,287
  • 1
  • 8
  • 19
1

I am just rephrasing the asked question with the above answer as the following script makes more sense to the first-timers:

var rightBorderOn = true;
var leftBorderOn =true;

var rightBorderColor = "red";  
var leftBorderColor = "blue";
  
range.setBorder( null, null, null, rightBorderOn, null, null, rightBorderColor, null );  
SpreadsheetApp.flush();
range.setBorder( null, leftBorderOn, null, null, null, null, leftBorderColor, null );
  

Hope this helps some!

Snail-Horn
  • 101
  • 11