M
M
Mistev2022-03-08 15:12:58
Google Apps Script
Mistev, 2022-03-08 15:12:58

How to paint the border of a merged cell using Google App Script?

Column "A" lists auto parts, many of the rows are merged (only in column "A"). After each spare part, there is a border in the entire line. I used to do them manually, today I decided to fix it with a script.

I’ll tell you about the script, how it works: Since I can’t know about all the additional properties of the spare parts in advance, I first remove all lower bounds through the loop, then I use this loop:

var ranges = [];

  for(var i = 1; i < firstColumn.length; i++)
  {
    if(firstColumn[i][0])
    {
      ranges.push("A" + i + ":" + i);
    }
  }

It determines where the merged cell ends and after that I paint over the border:
return sheet.getRangeList(ranges).setBorder(null, null, true, null, null, null);


Everything works as it should, but wherever there are merged cells, the border is not drawn.

How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2022-03-09
@oshliaer

Example https://docs.google.com/spreadsheets/d/1xa_zzf6P1n...
62282dc7c20f7732836185.png

function myFunction() {
  const book = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = book.getSheetByName('Sheet1');
  const ranges = ['B1', 'B4', 'B6', 'B9'];
  sheet.getRangeList(ranges).setBorder(null, null, true, null, null, null);
}

Everything works as it should.
You did not give a normal example, and this is your main mistake. You are most likely looking at the wrong part of the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question