merge cells in table using google script
function mergeCellsExample() {
//We can use an array of arrays to populate our table.
var cells = [
['First cell', 'Second cell'],
['First cell second row', 'Second cell second row']
];
//Creates an example document in your Google Drive Root Folder.
//It will be titled "Cell merge example"
var table = DocumentApp.create('Cell merge example').getBody().appendTable(cells);
// Get the first row in the table.
var row = table.getRow(0);
// Get the two cells this row.
var cell1 = row.getCell(0);
var cell2 = row.getCell(1);
// Check the contents of cells 1 and 2
Logger.log('Cell1 contents: %s', cell1.getText());
Logger.log('Cell2 contents: %s', cell2.getText());
// TableCell.merge() merges the current cell into its preceding sibling element.
var merged = cell2.merge();
Logger.log('Merged cell contents: %s', merged.getText());
// Cell1 and merged are the same cell
Logger.log('Cell1 == Merged cell: %s', cell1.getText() == merged.getText());
// Cell2 no longer exists
Logger.log('Cell2 contents: %s', cell2.getText());
}