代码示例
# -*- coding: UTF-8 -*-
import xlwt
def write_excel():
# 创建excel对象
f = xlwt.Workbook()
# 添加sheet页
sheet1 = f.add_sheet(u'sheet1', cell_overwrite_ok=True)
# 定义标题单元格格式
style_title = xlwt.XFStyle()
# 设置单元格内容自动换行
style_title.alignment.wrap = 1
# 设置标题单元格字体
font = style_title.font
# 设置标题单元格字体加粗
font.bold = True
# 设置填充颜色
pat = style_title.pattern
pat.pattern = 1
pat.pattern_fore_colour = 0x28
pat.pattern_back_colour = 0x28
# 设置单元格内容格式
style_title.num_format_str = 'general'
# 设置单元格边框
borders_title = style_title.borders
# 设置边框线的样式
borders_title.left = 2
borders_title.right = 2
borders_title.top = 2
borders_title.bottom = 2
# 设置单元格线的颜色
borders_title.left_colour = 0x08
borders_title.right_colour = 0x08
borders_title.top_colour = 0x0