Row height - auto value or what?

867 views
Skip to first unread message

Ervin Hegedüs

unread,
Apr 7, 2014, 2:39:53 AM4/7/14
to python...@googlegroups.com
Hello,

I'ld like to write a long text to an XLS cell - but the text
isn't wrapped, it shows in one line (if I select that cell, I see
the full content of cell).

How can I set the height of row, if I want to visible that long
text? When I set the height of ro to explicit 0, then the first 2
line of text are visible, but not more, and only in Libre Office,
in MS Office not.

Thanks for the help,


a.

Binoy Mathew

unread,
Apr 8, 2014, 2:19:10 AM4/8/14
to python...@googlegroups.com
Hi Ervin,

You can use easyxf (from xlwt) to define your styles for each cells.

##########

from xlwt import Workbook, XFStyle, Borders, Pattern, Font, easyxf, Formula

# and create a style like below.

       self.styleTableLeftColumn = easyxf("""
                                font:
                                    name sansSerif,
                                    color black,
                                    bold false,
                                    height 160;
                                borders:
                                    left thin,
                                    right 0,
                                    top 0,
                                    bottom thin,
                                    bottom_color light_blue,
                                    left_color light_blue;
                                align:
                                    wrap on,
                                    vert centre,
                                    horiz left;
                            """)       

# Now you can use this style while writing the contents in the cell -


wb = Workbook()
ws = wb.add_sheet('my sheet')

rowCount = 3
colCount = 1
data = 'ksjfhshfdwhsfd hwsfdwefdwefdfhnxnn denwqhed kj uguhgu ku ugkuhkhgfdtrdtfgygtfg kuhkuhkuhhhuhg'

ws.write(rowCount, colCount, data, self.styleTableLeftColumn)

wb.save(file_path)


Let me know if you need more help.

Regards,
Binoy Mathew










--
You received this message because you are subscribed to the Google Groups "python-excel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-excel...@googlegroups.com.
To post to this group, send an email to python...@googlegroups.com.
Visit this group at http://groups.google.com/group/python-excel.
For more options, visit https://groups.google.com/d/optout.

Ervin Hegedüs

unread,
Apr 8, 2014, 2:35:50 AM4/8/14
to python...@googlegroups.com
Hi Mathew,

thanks for the reply,

On Tue, Apr 08, 2014 at 11:49:10AM +0530, Binoy Mathew wrote:
> Hi Ervin,
>
> You can use easyxf (from xlwt) to define your styles for each cells.
>
> ##########

yes, I know, and I'm using that,

> from xlwt import Workbook, XFStyle, Borders, Pattern, Font, easyxf, Formula
>
> # and create a style like below.
>
> self.styleTableLeftColumn = easyxf("""
> font:
> name sansSerif,
> color black,
> bold false,
> height 160;
> borders:
> left thin,
> right 0,
> top 0,
> bottom thin,
> bottom_color light_blue,
> left_color light_blue;
> align:
> wrap on,
> vert centre,
> horiz left;
> """)

all cell's style has the "align: wrap True" attribute, but the
line doesn't wrap.

> # Now you can use this style while writing the contents in the cell -
>
>
> wb = Workbook()
> ws = wb.add_sheet('my sheet')
>
> rowCount = 3
> colCount = 1
> data = 'ksjfhshfdwhsfd hwsfdwefdwefdfhnxnn denwqhed kj uguhgu ku
> ugkuhkhgfdtrdtfgygtfg kuhkuhkuhhhuhg'

note, that I've try your example, and in that the line above also
doesn't wrapped (I've replace the ' separator to """)


but thanks for your help,


a.

Binoy Mathew

unread,
Apr 8, 2014, 3:46:43 AM4/8/14
to python...@googlegroups.com
Hi,

I tried below code and it wraps text in the column (when i removed 'align wrap on', i see long text with out wrapping.

#############


from xlwt import Workbook, XFStyle, Borders, Pattern, Font, easyxf, Formula

class ExcelClass():
    def __init__(self):
        # right aligned table contents

        self.styleTableLeftColumn = easyxf("""
                                font:
                                    name sansSerif,
                                    color black,
                                    bold false,
                                    height 160;
                                borders:
                                    left thin,
                                    right 0,
                                    top 0,
                                    bottom thin,
                                    bottom_color light_blue,
                                    left_color light_blue;
                                align:
                                    wrap on,
                                    vert centre,
                                    horiz left;
                            """)       
       
    def make_excel(self, file_path=None):

        wb = Workbook()
        ws = wb.add_sheet('my sheet')
        ws.show_grid = 0
        ws.col(0).width = 500
        rowCount = 1
        text = '499999999999999999999999999999999 999999999 9999999999999 99999999999999 9 9  9     999999999999 binoy mathew'
        ws.write(rowCount, 1, text, self.styleTableLeftColumn)
        wb.save(file_path)

if __name__ == '__main__':
    e = ExcelClass()
    file_path = "C:\\Users\\binoy\\Desktop\\ttt.xls"
    e.make_excel(file_path)



Regards,
Binoy Mathew





a.


Ervin Hegedüs

unread,
Apr 8, 2014, 6:11:30 AM4/8/14
to python...@googlegroups.com
Hi Mathew,

thanks,
- looks like you've tried on Windows - on Linux, I can't use "'"
(plain apostrophe), only """ (three quotation marks)
- in Libre Office, when I open the workbook, the text above shows
in one-line-height cell; when I click to that cell, that resize
itself


I'll lookup again,


thanks,


Ervin
Reply all
Reply to author
Forward
0 new messages