罫線を引くプログラムです。
プログラム
set_borders.py
#! /usr/bin/python
# ---------------------------------------------------------------
# set_borders.py
#
# Jun/18/2024
#
# ---------------------------------------------------------------
import sys
import openpyxl as xl
from openpyxl.styles.borders import Border, Side
# ---------------------------------------------------------------
xlsx_in=sys.argv[1]
xlsx_out=sys.argv[2]
bk = xl.load_workbook(xlsx_in)
ws = bk.worksheets[0]
print("ws.max_row = %d" % ws.max_row)
no_borders = xl.styles.borders.Border(top = None,bottom = None,
left = None, right = None,)
it = 1
side_thick = Side(style='thick', color='000000')
side_thin = Side(style='thin', color='000000')
border_left_thick = Border(left=side_thick)
border_both_thick = Border(left=side_thick,right=side_thick)
border_both_thin = Border(left=side_thin,right=side_thin)
border_bottom_thick = Border(bottom=side_thick)
border_bottom_left_thick = Border(bottom=side_thick,left=side_thick)
border_bottom_both_thin = Border(bottom=side_thick,left=side_thin,right=side_thin)
border_bottom_both_thick = Border(bottom=side_thick,left=side_thick,right=side_thick)
for row in ws.rows:
if 5 < it:
for cel in row:
cel.border = border_both_thin
ws.cell(it,4).border = border_both_thin
ws.cell(it,6).border = border_left_thick
ws.cell(it,9).border = border_left_thick
ws.cell(it,14).border = border_both_thick
if it == ws.max_row:
for cel in row:
cel.border = border_bottom_thick
ws.cell(it,2).border = border_bottom_both_thin
ws.cell(it,4).border = border_bottom_both_thin
ws.cell(it,7).border = border_bottom_both_thin
ws.cell(it,10).border = border_bottom_both_thin
ws.cell(it,12).border = border_bottom_both_thin
ws.cell(it,6).border = border_bottom_left_thick
ws.cell(it,9).border = border_bottom_left_thick
ws.cell(it,14).border = border_bottom_both_thick
it += 1
bk.save(xlsx_out)
# ---------------------------------------------------------------
実行方法
./set_borders.py in01.xlsx out01.xlsx