I'd like to write a table like this:
----------------
| Long Cell |
----------------
| 1 | 2 |
----------------
How to write the cell Long Cell
? Thanks.
I've tried to do it like this:
sheet.write(0, 0, 'Long Cell')
sheet.write(1, 0, 1)
sheet.write(1, 1, 2)
But it end up like:
--------------------
| Long Cell | |
--------------------
| 1 | 2 |
--------------------
As far as I can tell, this isn't documented - you have to read the source code to find it. There are two methods on the
Worksheet
class to do this,write_merge
andmerge
.merge
takes existing cells and merges them, whilewrite_merge
writes a label (just likewrite
) and then does the same stuffmerge
does.Both take the cells to merge as
r1, r2, c1, c2
, and accept an optionalstyle
parameter.From your example, this would be the simplest call:
To be more explicit about how the call works:
Alternatively, using
merge
:merge
has some comments in the source pointing out potential problems:But it would be fine for a simple case like this.