반응형
target파일에 source에 있는 시트를 붙여넣는 코드이다.
import win32com.client
def copy_sheet(source, target):
try:
excel = win32com.client.Dispatch("Excel.Application")
excel.Visible = False
excel.DisplayAlerts = False
wb1 = excel.Workbooks.Open(source)
wb2 = excel.Workbooks.Open(target)
source_ws = wb1.Worksheets("SourceSheet")
target_ws = wb2.Worksheets("TargetSheet")
source_ws.Range("A:Z").Copy(target_ws.Range("A:Z"))
wb2.Save()
except Exception as e:
print(e)
finally:
try:
wb1.Close()
wb2.Close()
except Exception as e:
print(e)
excel.Quit()
라이브러리설치
pip install pywin32
반응형
'프로그래밍 > python' 카테고리의 다른 글
selenium으로 web element를 찾아서 javascript로 조작하기 (0) | 2022.09.13 |
---|---|
파이썬 공휴일 가져오기 (++공공데이터 활용) python holidays 공휴일 포함 (0) | 2022.09.08 |
QWindowsContext: OleInitialize() failed: "COM error 0xffffffff80010106 RPC_E_CHANGED_MODE (Unknown error 0x080010106)" 오류 해결 법 (1) | 2022.09.07 |
input[type=file] 태그에 파일을 업로드 하는 방법 (0) | 2022.09.06 |
win32com.client.Dispatch("Excel.Application") 시트복사 및 시트명 변경 (0) | 2022.09.05 |