How to combine two table cells in a Google text document without this weird result?

I wrote this function (thanks, @Mogsdad) to combine cells in a table in a Google text document, for example:

enter image description here

function onOpen() { // Add a menu with some items, some separators, and a sub-menu. DocumentApp.getUi().createMenu('Sample') .addItem('merge cells of a table', 'mergeCells') .addToUi(); } function mergeCells() { var body = DocumentApp.getActiveDocument().getBody(); for (var p= 0; p< body.getNumChildren(); p++) { var child = body.getChild(p); if (child.getType() == DocumentApp.ElementType.TABLE){ // Assume we've already located our table var table = child; var tableRow = table.getChild(2); // gets third row var tableCell = tableRow.getChild(1); // gets second cell in row tableCell.merge(); // Merges seconde cell with first cell. } } } 

But when I run the code, I got this strange result (very different than expected, with a merged cell with the same table sizes):

enter image description here

Is there any way to fix this? (merged cell with the same dimensions)

+7
google-apps-script
source share
3 answers

[ edit to receive updates in Google Docs]

This is currently not possible. You can find out if a cell is merged by looking at the call to getColSpan and getRowSpan , but there are no configuration methods.

Please click the following problem to receive notifications about it.

The merge function that you discovered does not apply to table cells, it must combine any element with a previous relationship of the same type connecting their contents.


[ original answer]

If you were expecting to have a merged cell, which, like what you can do in a spreadsheet, this is not possible. Just because it’s not possible in Google Docs (at least for now). Therefore, the API cannot do this (it can only do what is also possible manually).

This merge function does not apply to table cells, as you probably imagine. It works as designed.

+10
source share

You can do this in a workaround. Add a drawing and add a table to this drawing document. In this document, the option "merge cell's" is possible if you select 2 cells and click the right mouse button. Watch this youtube tutorial video

+2
source share

Here's how to enable a merged cell in MS document tables when converting to a Google document. The idea is to go back to the MS Word document and delete the merged cells, and then copy and paste it or convert MS word to a Google document. Thus, we can easily convert tables in MS documents to Google documents. But in Google docs, a cell cannot be merged.

0
source share

All Articles