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

673次阅读
没有评论

共计 450 个字符,预计需要花费 2 分钟才能阅读完成。

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')

 

正文完
 0
zjh4473
版权声明:本站原创文章,由 zjh4473 于2021-12-12发表,共计450字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)