Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text alignment in xlwt with easyxf

Tags:

python

xlwt

I am using xlwt, excel sheet generation module for python. Basically I am trying to use some styles for the text. The coloring part works fine .i.e.

import xlwt

workbook = xlwt.Workbook(encoding='ascii')
worksheet = workbook.add_sheet('Test sheet')

worksheet.write(0, 0, "Hello World", xlwt.easyxf("pattern: pattern solid, fore_color yellow; font: color white;"))

There was a need to add alignment as well. I found this working

alignment = xlwt.Alignment()
alignment.horz = xlwt.Alignment.HORZ_RIGHT
horz_style = xlwt.XFStyle() 
horz_style.alignment = alignment
worksheet.write(0, 0, "Hello World", horz_style)

But now whole thing is messed up since I can use only either the coloring or alignment.What I am trying is to integrate the alignment feature with xlwt.easyxf as well

like image 800
beebek Avatar asked Nov 11 '13 07:11

beebek


1 Answers

It was as simple as adding align: horiz right

import xlwt

workbook = xlwt.Workbook(encoding='ascii')
worksheet = workbook.add_sheet('Test sheet')

worksheet.write(0, 0, "Hello World", xlwt.easyxf("pattern: pattern solid, fore_color yellow; font: color white; align: horiz right"))
worksheet.save()
like image 136
beebek Avatar answered Nov 19 '22 06:11

beebek