python 写入excel

不写BUG 1年前 ⋅ 900 阅读
import xlwt
# 创建一个workbook 设置编码
workbook = xlwt.Workbook(encoding = 'utf-8')
# 创建一个worksheet
worksheet = workbook.add_sheet('My Worksheet')

# 写入excel
# 参数对应 行, 列, 值
worksheet.write(1,0, label = 'this is test')
# 合并单元格
worksheet.write_merge(x, x + m, y, y + n, string, style)
styleBlueBkg = xlwt.easyxf('pattern: pattern solid, fore_colour ocean_blue; font: bold on;');  # 80% like
worksheet.write(i + 1, 7, rjson['list'][0]['diff'],styleBlueBkg if int(rjson['list'][0]['diff']) < 0 else xlwt.easyxf())
# 保存
workbook.save('Excel_test.xls')