xlwt bug (?) - doesn't autofit row height when text wrap is ON on merged cells

2,889 views
Skip to first unread message

dalia

unread,
Jun 6, 2011, 1:17:21 PM6/6/11
to python-excel
Hi All,

Could someone tell me if this is an existing known bug in xlwt. While
i write a long line with text wrap ON on a horizontally merged cells,
the row height is not automatically resized. my code snippet below -

data="A very long line which should be wrapped"
al1 = Alignment()
al1.horz = Alignment.HORZ_LEFT
al1.vert = Alignment.VERT_TOP
al1.wrap = Alignment.WRAP_AT_RIGHT

style1 = XFStyle()
style1.alignment = al1

worksheet.write_merge(2, 2, 1, 5, data, style1)

This does not adjust the row height. But when I write it in a single
cell, it works fine.

for example, worksheet.write(2, 1, data, style1) works fine, wraps the
text nicely, but it affects my row height and look and feel for other
cells.

Please help.

John Yeung

unread,
Jun 6, 2011, 3:54:08 PM6/6/11
to python...@googlegroups.com
Dalia,

As far as I can tell, merged cells do not automatically resize for
wrapped text, even in the genuine Microsoft Excel application.
Therefore, it's not a bug in xlwt.

What I do when I need to use multiple wrapped lines of text in a
single merged cell is to adjust the row height myself in xlwt (which
comes with its own set of gotchas).

John Y.

dalia

unread,
Jun 13, 2011, 7:03:47 AM6/13/11
to python-excel
Hi John,

But adjusting row heigh doesn't seem to have any effect. It seems the
row.height variable doesn't work at all. I know microsoft excel
doesn't adjust row height automatically but when I tried this using
pyXLWriter, it worked fine. pyXLWriter nicely wraps merged cells to
show the entire content.

Chris Withers

unread,
Jun 13, 2011, 10:59:56 AM6/13/11
to python...@googlegroups.com, dalia
On 13/06/2011 12:03, dalia wrote:
> But adjusting row heigh doesn't seem to have any effect. It seems the
> row.height variable doesn't work at all. I know microsoft excel
> doesn't adjust row height automatically but when I tried this using
> pyXLWriter, it worked fine. pyXLWriter nicely wraps merged cells to
> show the entire content.

It would be interesting to add that to xlwt if you could find the
relevant bits of pyXLWriter and work up a patch to add the same to xlwt...

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

John Machin

unread,
Jun 13, 2011, 5:33:14 PM6/13/11
to python...@googlegroups.com
On Monday, 13 June 2011 21:03:47 UTC+10, dalia wrote:
Hi John,

But adjusting row heigh doesn't seem to have any effect. It seems the
row.height variable doesn't work at all.

It does work, you just need to to fiddle with Row.height_mismatch ... search this group for row_height, read the discussion that took place around 2009-12-29.

 
I know microsoft excel
doesn't adjust row height automatically

Your googling with also bring up two previous discussions on this topic, the 2nd of which points to a glorious hack which can also be used in the UI:

https://groups.google.com/d/topic/python-excel/q0RKq1ZHQ8I/discussion
https://groups.google.com/d/topic/python-excel/sZgAclrGbPQ/discussion
http://excel.tips.net/T003207_Automatic_Row_Height_For_Merged_Cells_with_Text_Wrap.html
 
but when I tried this using
pyXLWriter, it worked fine. pyXLWriter nicely wraps merged cells to
show the entire content.


Please show the minimal RUNNABLE code to achieve "this" with pyXLWriter and the xlwt equivalent that doesn't work.

BTW I trust you don't actually plan to *use* pyXLWriter in production :-)
Reply all
Reply to author
Forward
0 new messages