1

Good afternoon.

In my project I need to generate xls files by content of the database.

I found for this python library xlwt, but I fased with a problem - how to format the cell so that the cell dimensions adjust to content? I.e. I need, that the cell width stretched, and if still not enough, cell height stretched and the contents came in a few lines.

Library docs very limited. I have looked in the githabe examples, but not found the solution of this problem.

I have wrote to the group on Google, which discusses the work of the xlwt library, but my message have not even posted in access (not passed moderation).

Can someone tell me here?

Or maybe some more convenient tool for solving my problem?

savao
  • 103
  • 7
  • 1
    Existing question, non-trivial answer, take a look -> http://stackoverflow.com/questions/6929115/python-xlwt-accessing-existing-cell-content-auto-adjust-column-width – salezica Mar 18 '14 at 15:53
  • 2
    Either a duplicate of the above, or can be answered by [this](http://pythonexcels.com/python-excel-mini-cookbook/). – WGS Mar 18 '14 at 15:54
  • On this link I don't found the answer. – savao Mar 18 '14 at 16:47
  • On this link is recipe for windows, but I use linux OS – savao Mar 18 '14 at 16:48
  • I found answer in http://python.su/forum/topic/21690/?page=1#post-111070 . One can use the "alignment" property of the object style for solving this problem – savao Mar 18 '14 at 16:50

1 Answers1

0

You can style the text like given below in sample code.

import xlwt
import os
import subprocess
from xlwt import Workbook
from  tempfile import NamedTemporaryFile
book = Workbook()
sheet1 = book.add_sheet('Sheet 1',  cell_overwrite_ok = True)
styleText = 'font: name Calibri,height 220;align:vertical center, wrap on;'
style = xlwt.easyxf(styleText)
sheet1.write(0, 0, "This is long long content of cell" , style=style )
file = NamedTemporaryFile(suffix=".xls", delete=False)
book.save(file)
file.close()
path = os.path.abspath(file.name)
subprocess.Popen('start ' + path, shell=True)

The wrap on will wrap the text.

hsvyas4u
  • 158
  • 2
  • 9