我想知道如何在一个变量中添加不同的格式,如字体,背景颜色,百分比格式,调色板颜色和更多,例如我将选择变量样式。
请指教
style5 = xlwt.easyxf(' pattern : pattern solid,fore_colour gray25;')
style_percent = xlwt.easyxf(num_format_str='0.00%')
上面的代码附件显示,我已经创建了两个变量和背景颜色和百分比符号已分别格式化,在实际中,我想使用一个变量,并添加该变量的所有这些格式,例如,我只想创建style5,并想添加模式和num_format_str在其中。我怎么能做到这一点。
发布于 2019-06-28 17:38:08
看看这个
Views.py
def export_styling_xls(request):
response = HttpResponse(content_type='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename="users.xls"'
wb = xlwt.Workbook(encoding='utf-8')
ws = wb.add_sheet('Styling Data') # this will make a sheet named Users Data - First Sheet
styles = dict(
bold = 'font: bold 1',
italic = 'font: italic 1',
# Wrap text in the cell
wrap_bold = 'font: bold 1; align: wrap 1;',
# White text on a blue background
reversed = 'pattern: pattern solid, fore_color blue; font: color white;',
# Light orange checkered background
light_orange_bg = 'pattern: pattern fine_dots, fore_color white, back_color orange;',
# Heavy borders
bordered = 'border: top thick, right thick, bottom thick, left thick;',
# 16 pt red text
big_red = 'font: height 320, color red;',
)
for idx, k in enumerate(sorted(styles)):
style = xlwt.easyxf(styles[k])
ws.write(idx, 0, k)
ws.write(idx, 1, styles[k], style)
wb.save(response)
return responsehttps://stackoverflow.com/questions/56515287
复制相似问题