Openpyxl Library란?
Openpyxl은 Python에서 Excel File을
자동으로 수정하도록 프로그램을 작성할 수 있는 라이브러리이다.
Reference
Openpyxl 제공 사이트
우선, 터미널에서 pip 레포지토리에 openpyxl
라이브러리를 가져옵니다.
pip
는 pip3
에 소프트 링크 걸려있을 가능성이 높습니다.
pip3 install open
파이썬 라이브러리를 작업할 파이썬 파일에 가져옵니다.
import openpyxl
* 객체 생성
A workbook is always created with at least one worksheet. You can get it by using the Workbook.active property:
wb = Workbook() ws = wb.active
* Work Sheet Create
# There are three methods
ws1 = wb.create_sheet("Mysheet") # insert at the end (default)
ws2 = wb.create_sheet("Mysheet", 0) # insert at first position
ws3 = wb.create_sheet("Mysheet", -1) # insert at the penultimate position
penultimate
: 끝에서 두번째
* Work Sheet Title
Sheets are given a name automatically when they are created. (Sheet, Sheet1, Sheet2, …)
ws.title = "New Title"
Once you gave a worksheet a name, you can get it as a key of the workbook:
ws3 = wb["New Title"]
Only cells (including values, styles, hyperlinks and comments) and certain worksheet attribues (including dimensions, format and properties) are copied. All other workbook / worksheet attributes are not copied - e.g. Images, Charts.
You also cannot copy worksheets between workbooks. You cannot copy a worksheet if the workbook is open in read-only or write-only mode.
1) 카피 되는 것이 있고 아닌 것이 있다. (EX: 이미지, 차트)
2) 워크북 사이에서는 copy 할 수 없고
3) 워크북이 read-only, wriply 면 copy 할 수 없다.
print(wb.sheetnames)
(Output) ['Seet2', 'New Title', 'Sheet1']
for sheet in wb:
print(sheet.title)