openpyxl セルの背景色 | 60歳を迎えて、思うこと。

60歳を迎えて、思うこと。

いつの間にか、「60」という年月が経ちました。
残り少ないか多いか?わかりませんが。
じじぃ~の「ひとりごと」を細々と続けられれば。。。

openpyxl セルの背景色

# puthon

# openpyxl

# 背景色

# 色塗り

むひむひ
どんどん

YouTubeで
pythonの文法を
勉強していたのは
と~~~い むかし

その頃に書いた
すくりぷと

じじぃ~ なりに 改造

ぶひ!

# ==== 共通 旧と改造版
# ==== 背景色の 色指定 着色範囲
# ==== 背景色を変更 背景色

fill = openpyxl.styles.PatternFill(patternType='solid',
                                   fgColor='FF0000', bgColor='FF0000') # 真っ赤
                                   # fgColor='F0E68C', bgColor='F0E68C') # カーキ色 クリーム色 うすい黄色


# ==== 旧書き方
# ==== 変数 line_no_back_color で 2行目指定

line_no_back_color = 2 # 2行目

ws.cell(row=(line_no_back_color),column=1).fill = fill      # A列
ws.cell(row=(line_no_back_color),column=2).fill = fill      # B列
ws.cell(row=(line_no_back_color),column=3).fill = fill      # C列
ws.cell(row=(line_no_back_color),column=4).fill = fill      # D列
ws.cell(row=(line_no_back_color),column=5).fill = fill      # E列
ws.cell(row=(line_no_back_color),column=6).fill = fill      # F列
ws.cell(row=(line_no_back_color),column=7).fill = fill      # G列
ws.cell(row=(line_no_back_color),column=8).fill = fill      # H列

# ==== おわり


# ==== 改造版 書き方
# ==== 背景の塗る場所 指定
for row in ws["A2:H2"]: # 項目名行
    for cell in row:
        cell.fill = fill
# ==== おわり

うん!
すっきり・・・

じじぃ~