xlsxwriter【1.1.2】设置单元格格式

版权声明:版权所有,翻版必究【Kevin】 https://blog.csdn.net/weixin_30935137/article/details/84075933

字典方式设置单元格格式

#通过字典的方式直接设置格式

workfomat = workbook.add_format({
    'bold' : True,                 #字体加粗
    'border' : 1,                    #单元格边框宽度
    'align' : 'center',          #对齐方式
    'valign' : 'vcenter',         #字体对齐方式
    'fg_color' : '#F4B084',         #单元格背景颜色
})

format对象方式设置单元格格式

#通过format对象的方式设置单元格格式
cell_format1 = workbook.add_format()
cell_format1.set_bold() #加粗,True/False
cell_format1.set_font_name('Times New Roman')#字体类型
cell_format1.set_font_color('red')#字体颜色
cell_format1.set_font_size(15)#字体大小
cell_format1.set_align()#对齐方式
cell_format1.set_bg_color()#背景色
cell_format1.set_italic()#斜体
cell_format1.set_underline()#下划线

猜你喜欢

转载自blog.csdn.net/weixin_30935137/article/details/84075933