-
Notifications
You must be signed in to change notification settings - Fork 0
/
51_엑셀_셀_서식지정.py
41 lines (32 loc) · 1.32 KB
/
51_엑셀_셀_서식지정.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import openpyxl
from openpyxl.styles import Font, Alignment, PatternFill, Border, Color, Side
book = openpyxl.load_workbook("./엑셀/광고비_토탈.xlsx")
sheet = book.active
#서식만들기
user_font = Font(name="맑은 고딕", size=12, bold=True)
user_alignment = Alignment(horizontal="center")
orange_color = PatternFill(patternType="solid", fgColor=Color("FE9A2E"))
gray_color = PatternFill(patternType="solid", fgColor=Color("BDBDBD"))
user_boder = Border(left=Side(style="thin") , right=Side(style="thin") , top=Side(style="thin") , bottom=Side(style="thin"))
sheet["A14"].value = "합계"
sheet["A14"].font = user_font
sheet["A14"].alignment = user_alignment
sheet["A14"].fill = orange_color
sheet["A14"].border = user_boder
sheet["B14"].value = "=sum(B2:B13)"
sheet["C14"].value = "=sum(C2:C13)"
sheet["D14"].value = "=sum(D2:D13)"
#여러 셀 서식지정 한번에
for row in sheet["B14:D14"]:
for cell in row:
cell.font = user_font
cell.alignment = user_alignment
cell.fill = orange_color
cell.border = user_boder
for row in sheet["B2:D13"]:
for cell in row:
cell.font = user_font
cell.alignment = user_alignment
cell.fill = gray_color
cell.border = user_boder
book.save("./엑셀/광고비_토탈_서식지정.xlsx")