我是靠谱客的博主 知性流沙,这篇文章主要介绍python openpyxl的简单使用和设置单元格背景色,现在分享给大家,希望可以做个参考。


def pyxl_execl():
import openpyxl
wb = openpyxl.Workbook()
ws = wb.active
ws.title = '麦嘎'
data = [(1, 2, 3, 4), ('djdj', 'dkdk', '', 'djdj'), (23, 98, 'dk', 'kdkd')]
fill = openpyxl.styles.PatternFill("solid", fgColor="1874CD")#颜色也可以直接设置red等
row0 = ('姓名', 'name', 'age', 'core')
for i, r in enumerate(row0):
ws.cell(row=1, column=i + 1, value=r)
for i, r in enumerate(data):
for j, c in enumerate(r):
if i%2 == 1:
ws.cell(row=i + 2, column=j + 1).fill = fill
ws.cell(row=i + 2, column=j + 1, value=c)
wb.save('./测试.xlsx')
if __name__ == '__main__':
pyxl_execl()

 

最后

以上就是知性流沙最近收集整理的关于python openpyxl的简单使用和设置单元格背景色的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(120)

评论列表共有 0 条评论

立即
投稿
返回
顶部