M
M
Mistev2022-03-09 09:37:40
Google Apps Script
Mistev, 2022-03-09 09:37:40

What function can be used to find out how many cells are merged?

Tell me, with what function can I find out the exact number of combined rows and columns in one cell?
There are features such as:

getRowSpan()
getColumnSpan()


But there is no example of how to apply them anywhere. If I use them myself, it gives an error that they are not declared.

Answer the question

In order to leave comments, you need to log in

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

Example in Spreadsheet https://docs.google.com/spreadsheets/d/1mkUDHVX1b5...
TryRange.isPartOfMerge()

function myFunction() {
  const book = SpreadsheetApp.getActiveSpreadsheet();
  const range = book.getRange('C5');
  const mergedRange = range.getMergedRanges()[0];
  if (mergedRange) {
    const countCells = mergedRange.getValues()[0].length * mergedRange.getValues().length;
    console.log('Входит в объединенную ячейку?', range.isPartOfMerge());
    console.log('Диапазон объединения:', mergedRange.getA1Notation());
    console.log('Количество объединенных ячеек:', countCells);
    console.log('Количество строк в объединенном диапазоне:', mergedRange.getValues().length);
  } else {
    console.info('Ячейка не объединена');
  }
}

622a11222454e176897771.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question