[英]Using xlsxwriter to colour an individual cell
I want to use xlsxwriter to set properties like background color, font color, font type, font size etc. for one single cell only.我想使用 xlsxwriter 为单个单元格设置背景颜色、字体颜色、字体类型、字体大小等属性。
I am finding methods like.set_rows() and.set_columns().我正在寻找像.set_rows() 和.set_columns() 这样的方法。 Is there any way to access only 1 particular cell.
有没有办法只访问一个特定的单元格。
Thanks in advance提前致谢
You can use xlswriter library in order to format individual formats like in the following example您可以使用xlswriter库来格式化单个格式,如下例所示
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.