0
from xlsxwriter import Workbook
from string import ascii_lowercase
letters=ascii_lowercase
workbook = Workbook('Expenses01.xlsx')
worksheet = workbook.add_worksheet('Results')
worksheet.set_column('K:K', None, None, {'hidden': True})
worksheet.set_column('O:O', None, None, {'hidden': True})
row=0
cell_format = workbook.add_format()
cell_format.set_bold()
cell_format.set_bg_color('brown')
cell_format.set_pattern(1)
cell_format.set_font_color('red')
worksheet.write(0, letters.index('j'),'PLEASE FILL PRICES IF FULL DATA PROVIDED',cell_format)

How can I change the cell size so entire text is shown, I don't want to change entire column size just this "header" cell. (i.e allow text to be written in two lines in one cell)

after adding cell_format.set_text_wrap()

this is output image

programmerwiz32
  • 529
  • 1
  • 5
  • 20
  • Possible duplicate of [Adjust cell width in Excel](https://stackoverflow.com/questions/33665865/adjust-cell-width-in-excel) – AnsFourtyTwo Aug 28 '19 at 13:10

2 Answers2

1

(i.e allow text to be written in two lines in one cell)

This makes it seem like you want text wrapping within the cell. The Format class has a set_text_wrap() method that does this. Simply add the following line after your other format configuration.

cell_format.set_text_wrap()
Chathan Driehuys
  • 1,173
  • 3
  • 14
  • 28
  • @programmerwiz32 Can you manually create a spreadsheet containing your desired output and provide a screenshot? It is hard to understand what your desired outcome is. – Chathan Driehuys Aug 28 '19 at 19:44
0

You have to use: cell_format.set_text_wrap()

If you wish to adapter the height of the cell according to the text, you can use: set_align('vjustify')

This information can be found at: https://xlsxwriter.readthedocs.io/format.html

AnsFourtyTwo
  • 2,480
  • 2
  • 13
  • 33
  • Seems like there is no direct solution to your problem. You cannot fit your cell size to the text in your cell. Either you set the width of the cell manually or you make use of `win32com` – AnsFourtyTwo Aug 28 '19 at 13:13