I've seen many pages on here to format the width of an entire column, but is there a way to format an individual cell width? My issue is that I'm creating a sheet that has a "header" more or less, several rows where each column is a different length because they're been mergered to include unique information. Below this section will be a standard dataframe, which the entire column's width will need to be formatted to the data. But for the first five rows I need to specify unique width values. Is this possible?
Asked
Active
Viewed 2,063 times
3
-
may be this would help you: https://stackoverflow.com/questions/51631138/writing-text-wrapped-excel-files-using-python-solved – anky Dec 30 '18 at 14:07
-
1You want to format the width of columns in the first 5 rows different from those in the following rows? How should that be possible in _one table_? You can merge columns in excel .. you might be able to hack around with that - but it makes it quite complicated – Patrick Artner Dec 30 '18 at 14:11
-
I think the OP means wrapping up the texts. Surely width changing should not be possible for diff rows in same column. – anky Dec 30 '18 at 14:12
1 Answers
4
xlswriter has a format feature saying how to change the properties of the spreadsheet cell: https://xlsxwriter.readthedocs.io/format.html
import xlsxwriter
# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('Expenses01.xlsx')
worksheet = workbook.add_worksheet()
cell_format = workbook.add_format()
cell_format.set_bold()
cell_format.set_font_color('red')
There are properties to do everything including change the width of the cell.

Eric Leschinski
- 146,994
- 96
- 417
- 335

Jorge
- 2,181
- 1
- 19
- 30