In a Google docs spreadsheet. If cells A1 & A2 are merged, is there a way to confirm they are merged, using google apps script?
There is a merge function in GAS https://developers.google.com/apps-script/class_range#merge
But there is no function or example that shows how to check if cells are merged.
getValues etc just returns an empty string for the cell. e.g. this does not work.
function testMerge() {
var spreadsheet = SpreadsheetApp.openById('Z3ppTjxNUE........');
var sheet = spreadsheet.getSheets()[0];
var range = sheet.getRange("A3:A4");
var values = range.getValues();
var formulas = range.getFormulasR1C1();
var formulasA1 = range.getFormulas();
range = sheet.getRange("A4");
range.setValue("a");
range = sheet.getRange("A3:A4");
var values2 = range.getValues();
var formulas2 = range.getFormulasR1C1();
var formulasA12 = range.getFormulas();
var count = range.getHeight();
}
Click Alignment > Merge cells > OK. Click Find All to see a list of all merged cells in your worksheet. When you click an item in the list, Excel selects the merged cell in your worksheet. You can now unmerge the cells.
Shortcuts to Unmerge Cells You can select the merged cells and use the Ctrl + \ shortcut that removes formatting to unmerge them. But, keep in mind it will also remove all other formatting.
In order to unmerge them at once, you have to select all cells in the sheet (by clicking the arrow in the left upper corner of the cells, or using the keyboard shortcut CTRL + A). Then in the Ribbon, go to Home > Merge & Center. As a result, all merged cells are now split into their original cells.
Yes, now you can use isPartOfMerge
to check.
And for anyone wants to get the value of merged cell:
var value = (cell.isPartOfMerge() ? cell.getMergedRanges()[0].getCell(1,1) : cell).getValue();
Hope it help.
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