B
Okay. This issue is nothing different from that. https://stackoverflow.com/a/39058303/1393023 ♪Let's say we have some method of connecting the cells:function verticallyMerger(sheet, blocks){
/*
{
columns: [],
rows: [[index, count],[index, count]]
}
*/
for (var i = 0; i < blocks.rows.length; i++){
for (var j = 0; j < blocks.columns.length; j++){
sheet.getRange(blocks.rows[i][0], blocks.columns[j], blocks.rows[i][1]).mergeVertically();
}
}
return sheet;
}
It's pretty transparent:We're going to.applied in turnThere is a need to add a more and less useful designer of the building blocks. For example,function blockBilder(sheet, initialBlocks){
var blocks = initialBlocks;
blocks.rows = [];
var values = sheet.getRange(1, blocks.mergerColumn, sheet.getLastRow()).getValues();
var isNew = true;
var prevVal;
for(var i = 0; i < values.length; i++){
if(prevVal === values[i][0]){
if(isNew){
blocks.rows.push([i , 2]);
isNew = false;
} else {
blocks.rows[blocks.rows.length - 1][1]++;
}
} else {
prevVal = values[i][0];
isNew = true;
}
}
return blocks;
}
It's not clear, of course. initialBlocks is obliged to represent an object like this.{
mergerColumn : 2
}
mergerColumn - Column number, on the basis of which it will be concluded that it is necessary to combineNow you can start.function run(){
var sheet = SpreadsheetApp.getActiveSheet();
var blocks = blockBilder(sheet, {mergerColumn : 2, columns: [2, 3, 4, 5, 6]});
verticallyMerger(sheet, blocks);
}
♪ blocks Another characteristic that is necessary for verticallyMerger - That's it. columns♪ It contains a set of columns for integration. https://gist.github.com/oshliaer/844c9c135233f37ce985a88c036e8644 A copy of the working example and the code is available in full.