Does anyone have an example of how/if we can set the row/colspan on a TableCell (?) Element in an Apps Script generated Google Document?
Does this need to be done using the .setAttributes() method?
Does anyone have an example of how/if we can set the row/colspan on a TableCell (?) Element in an Apps Script generated Google Document?
Does this need to be done using the .setAttributes() method?
i found this question, because i wanted to get rid of a RowSpan within a table and searched for an answer to the question "How can i set RowSpan or ColSpan to 1.
As you lot did, i had to realize that there is no way to get writable access to these hidden properties of a TableCell.
But on my research i found an answer to this question. It's an uncomfortable workaround, but once when it is set up properly, it works very nice:
The key is that you can delete a cell and replace it by a deep copy of a cell, which you spanned manually before.
If you have a table with some spanning cells, created manually, for example a table with 3 rows and 3 cells, which you spanned them all, then you can make a deep detached copy of the spanning cell and insert it anywhere in another table. The inserted cell in the destination table will span the surrounding cells as it does in the source table.
You have to know that the contents of the surrounding cells are still there, but cannot be seen. And if you delete the spanning cell again or you do the unspanning manually, they will be shown again.
This insert of the already spanning srcCell has the same effect as if you would lay a 3x3 cells overlapping white paper on the destination table. All the cells are still there, but you can't see them. The guugel-doc engine shows only the contents of the spanning cell.
And this behavior can be copied. Isn't that nice?
I know, this is a moloch, if you have to span many cells with many different spanning-widths and directions, but if you designed it for your needs, it maybe worth the time you have to spend for the spanning cell patterns.
One could create a document, which holds only tables with all the spanning cells, you need. And you can use this document as your "Spanning Cells Source".
You can make a copy of the following test-document, which contains 3 tables and clearly shows the principle behind it. The first table holds a 3x3 spanning cell at tableindex 0,0. The second table holds the indexes of each cell in the cell itself as row,col pairs and a "TestCell", which should span 3x3 other cells. The 3rd table is for comparison only:
https://docs.google.com/document/d/1G8C2JP_4689RFmtxHZ2djslwoGWwHwieHfbIwr2XzeQ/edit
And then you have access to the bound script, which preserves the contents of the "TestCell", replaces it by a 3 times 3 spanning cell and puts the content back again. You will see the following bound script:
I hope, this can help.
Thank you very much for your attention,
Richard
I have discovered a very kludgy workaround for the lack of
colspan
in GAS...FlexTable
,Grid
, etc.) with the columns/row you wantcolspan
orrowspan
, create a new table (with different cell widths and heightsVerticalPanel
and add each of the tables you created in steps 1-3 in orderYou now have the appearance of a single table with
colspan
androwspan
features.Not very elegant, but it's the only solution I've been able to come up with.
No, there is currently no way to do this. I don't see a feature request on the Issue Tracker, either.
There is a
.merge()
method on theTableCell
object, which sounds promising. However, when it's used it combines the "current" TableCell object with the "previous" sibling TableCell by appending the content of the "current" TableCell to the "previous" one, then deleting the "current" one.Before
After
Code
I modified the code from a previous answer to experiment with
.merge()
, here it is: