Using xlsxwriter to colour an individual cell

Viewed 680

I want to use xlsxwriter to set properties like background color, font color, font type, font size etc. for one single cell only.

I am finding methods like .set_rows() and .set_columns(). Is there any way to access only 1 particular cell.

Thanks in advance

1 Answers

You can use xlswriter library in order to format individual formats like in the following example

import xlsxwriter

# Create a new Excel file and add a worksheet.
wb = xlsxwriter.Workbook('mydocument.xlsx')
ws = wb.add_worksheet()

# Widen the first two columns
ws.set_column('A:B', 20)

# Write a non-formatted text 
ws.write('A1', 'fox jumped')

# Define a format and add some attributes in order to highlight the related cells
frm1 = wb.add_format({'bold': True})
frm1.set_font_color('#FF0000')
frm1.set_bg_color('#808080')

ws.write('A2', 'over the lazy dog', frm1)


# Define a format and add attributes at once
frm2 = wb.add_format({'italic': True,'border': 1,'bg_color': '#FFC7CE','font_color': '#9C0006'})

ws.write('B1','over the lazy dog',frm2)

wb.close()
Related