xlwt 写sheet xls 文件

import xlwt
workbook = xlwt.Workbook()#创建book
worksheet = workbook.add_sheet('My Sheet') #添加sheet
#背景色的添加
pattern = xlwt.Pattern() # Create the Pattern
pattern.pattern = xlwt.Pattern.SOLID_PATTERN # May be: NO_PATTERN, SOLID_PATTERN, or 0x00 through 0x12
pattern.pattern_fore_colour = 5 # May be: 8 through 63. 0 = Black, 1 = White, 2 = Red, 3 = Green, 4 = Blue, 5 = Yellow, 6 = Magenta, 7 = Cyan, 16 = Maroon, 17 = Dark Green, 18 = Dark Blue, 19 = Dark Yellow , almost brown), 20 = Dark Magenta, 21 = Teal, 22 = Light Gray, 23 = Dark Gray, the list goes on...
style = xlwt.XFStyle() # Create the Pattern
style.pattern = pattern # Add Pattern to Style
worksheet.write(0, 0, 'Cell Contents', style)
worksheet.write(0, 1, '2', style)
workbook.save('Excel_Workbook.xls')#保存文件



posted @ 2017-11-09 16:21  任飞儿  阅读(1613)  评论(0编辑  收藏  举报