openpyxl - Gakgu/Gakgu.github.io GitHub Wiki

개요

파이썬에서 엑셀 파일에 접근, 조작이 가능하게 만든 라이브러리.

공식 홈페이지

https://openpyxl.readthedocs.io

사용법

엑셀 파일 생성, 열기

excel = openpyxl.Workbook()
excel = openpyxl.load_workbook("./fixs.xlsx")

시트

# 시트 생성하기
sheet = excel.create_sheet('new sheet')

# 활성화된 시트 얻기
sheet = excel.active

# 시트 이름으로 얻기
sheet = excel[sheetname]

# 모든 시트 접근하기
for sheet in excel:
    pass

행, 열 접근하기

for row in range(0, 100):
    sheet.cell[row, 1]

값 얻기

# cell 번호로 얻기
value = sheet[row, column].value

저장 및 종료

excel.save()
excel.close()