MoonNote

반응형
     

 

 

엑셀 파일

Sample Sheet File.xlsx
0.01MB

 

엑셀 파일 구성

예제 실행시 사용하였던 엑셀 파일 데이터 및 시트 정보

▪ 3행 4열 데이터셋

셀 데이터

▪ 3개 시트로 구성

엑셀 시트 정보

 

엑셀 시트 복사

import openpyxl

from openpyxl import workbook

# You must change the physical path before running this script.
currPath = "C:/Users/natio/OneDrive - 성균관대학교/99. Personal Blog/05. Python/05. OPENPYXL_XLRD_XLWT/01. Excel Sheet/"

# Load the excel file
wb = openpyxl.load_workbook(filename=currPath+"Sample Sheet File.xlsx")

# Copy Sheet
wb.copy_worksheet(wb["Sample Sheet"])

# Copied sheet Name is added 'Copy' at the end of the name.
print(wb.sheetnames)

Result

['Sample Sheet', 'Sample Sheet (2)', 'Sample Sheet (3)', 'Sample Sheet Copy']

 

엑셀 시트 이름 변경

import openpyxl

from openpyxl import workbook

# You must change the physical path before running this script.
currPath = "C:/Users/natio/OneDrive - 성균관대학교/99. Personal Blog/05. Python/05. OPENPYXL_XLRD_XLWT/01. Excel Sheet/"

# Load the excel file
wb = openpyxl.load_workbook(filename=currPath+"Sample Sheet File.xlsx")

# Copy Sheet
copy_Sheet = wb.copy_worksheet(wb["Sample Sheet"])

# Copied sheet Name is added 'Copy' at the end of the name
print(wb.sheetnames)

# Change the copied sheet name
copy_Sheet.title = "Duplicate Sheet"

# Confirm the Sheet names
print(wb.sheetnames)

Result

['Sample Sheet', 'Sample Sheet (2)', 'Sample Sheet (3)', 'Sample Sheet Copy']
['Sample Sheet', 'Sample Sheet (2)', 'Sample Sheet (3)', 'Duplicate Sheet']

 

Openpyxl 함수 모음

 

 

 

 

※ 이 글이 도움이 되었다면 "🤍공감" 버튼을 클릭해주세요. 클릭 한번이 글 쓰는데 큰 힘이 됩니다.

 

 

 

공유하기

facebook twitter kakaoTalk kakaostory naver band