Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xlsxwriter format specific cell

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?

like image 492
Chris Macaluso Avatar asked Jun 13 '26 22:06

Chris Macaluso


1 Answers

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.

like image 89
Jorge Avatar answered Jun 15 '26 11:06

Jorge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!