Pythonでエクセル操作2
- hiro2studio
- 2021年1月31日
- 読了時間: 1分
昨日のプログラムを変更して数値部分に罫線を入れてみる
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import openpyxl as ex
from openpyxl.styles.borders import Border, Side
#-------------------------------------------------
## main ###
#-------------------------------------------------
if __name__=='__main__':
file_name = '6x6.xlsx'
excelBook = ex.load_workbook(file_name)
ws = excelBook.worksheets[0]
# 罫線設定--------------------------
side = Side(style='thin', color='000000')
border = Border(top=side, bottom=side, left=side, right=side)
# ---------------------------------
for row in ws.rows:
addrs = []
value = []
for cell in row:
if (cell.value > 10) & (cell.value < 20):
cell.font = ex.styles.fonts.Font(color='FF0000')
# 設定した罫線入れる
cell.border = border
excelBook.save(file_name)

Comments