[python] openpyxl 的一些使用上的小问题记录一下

1、获取sheet直接使用数组形式:

sheet = work_book['Sheet0']

2、取单元格值是value

some_value = sheet.cell(row=1, column=1).value

3、遍历行 列的方法

# 这个的索引是从1开始的,最后max+1是为了最后一行可以匹配到

# 遍历行
for row in range(begin_row_index, sheet.max_row + 1):
 # some code
 break

# 遍历列

# 遍历行
for column in range(begin_column_index, sheet.max_column + 1):
 # some code
 break

4、填充,字体等设置方法

# 设置颜色 具体函数内容请阅读文档
sheet.cell(row=1, column=1).font = Font(color='FF0000')

# 设置填充
sheet.cell(row=1, column=1).fill = PatternFill(patternType='solid', fgColor='FF0000')

 

版权声明:
作者:zjh4473
链接:https://blog.zixutech.cn/?p=681
来源:紫旭Blog
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>