I would like to write a script that copies the formatting, and the conditional formatting, that is applied to cell A1, and applies it to all of the other cells in the sheet.
However, I do not want to copy the merged-cell-status of A1.
For example, if A3 and B3 are merged, and if A1 is not merged with any other cell, then I want all of the formatting of A1 (both conditional and non-conditional) to be copied to the other cells, including A3 and B3, but in a way that preserves the merged status of A3 and B3 (or any other merged cells).
A B C
_______________
1| | | |
2| | | |
3| | |
4| | | |
I've tried the following functions, but both of these end up unmerging A3 and B3.
function copyFormat() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getRange('A1');
var destination = ss.getRange('A2:A');
source.copyTo(destination, {formatOnly:true});
}
and
function setFormat(){
var ss = SpreadsheetApp.getActive()
var sheet = ss.getActiveSheet()
var firstCell = sheet.getRange(1, 1, 1, 1)
var dataRange = sheet.getDataRange()
firstCell.copyFormatToRange(sheet, 1, dataRange.getNumColumns(), 1, dataRange.getNumRows())
}