素手烹茶|“蟒蛇”py对Excel的读取——数据操作用它,老板都得重新认识你( 五 )


workbook.save('Excel_Workbook.xls')
Setting the Background Color of a Cell
import xlwt
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('My 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)
workbook.save('Excel_Workbook.xls')
TODO: Things Left to Document
- Panes -- separate views which are always in view
- Border Colors (documented above, but not taking effect as it should)
- Border Widths (document above, but not working as expected)
- Protection
- Row Styles
- Zoom / Manification
- WS Props?
Source Code for reference available at:
上面这个例子是一个想学习Python办公自动化这块的一个案例分享 , 内容比较简单 , 非常容易上手 , 大家感兴趣的可以在评论区留言或者讨论 。
当然 , 关注点赞+评论:学习 , 找我领取一些这方面的书籍和视频教程 , 可以作为福利分享给大家!
【素手烹茶|“蟒蛇”py对Excel的读取——数据操作用它,老板都得重新认识你】文章分享希望对大家有所帮助 , 感谢支持!喜欢的关注我主页会分享更多的干货知识 , 我是进击程序员 , 喜欢的点个赞吧!
素手烹茶|“蟒蛇”py对Excel的读取——数据操作用它,老板都得重新认识你


推荐阅读