Excelでセルの結合をしつつ、中央揃えにする。
例)D1:F1からD14:F15を結合し、中央揃え
import openpyxl as px
from openpyxl.styles import Alignment ← 中央揃えのためインポート
wb2 = px.load_workbook('Book2.xlsx')
ws2 = wb2['Sheet1']
#whileを使用し、14回まで数値を追加しつつループさせる。
i = 1
while i < 15:
ws2.merge_cells('D'+ str(i) + ':F' + str(i))
# B2セルに[中央揃え]を設定
ws2['D' + str(i)].alignment = Alignment(horizontal='center')
i += 1
#bブックを「copy4」で保存する
wb2.save(filename = 'Book2.xlsx')