xlstoxlsx.py--------------------
# xls to xlsx
import win32com.client
fname = r"E:\python\vscode\pay\급여s1.xls"
# excel = win32.gencache.EnsureDispatch('Excel.Application') ##################
excel = win32com.client.Dispatch("Excel.Application")
excel.Visible =False
# wb = excel.Workbooks.Add() ##################################################
wb = excel.Workbooks.Open(fname)
ws = wb.Worksheets('4대급여')
ws.Cells(2,1).Value = "win32com excel test1"
ws.Range("A3").Value = "win32com excel test2"
wb.SaveAs(fname+"x", FileFormat = 51) #FileFormat = 51 is for .xlsx extension
# wb.Save() # 기본파일경로에 저장 ###############################################
wb.Close() #FileFormat = 56 is for .xls extension
excel.Application.Quit()
# xlsx to xls
# import win32com.client
# excel = win32com.client.Dispatch('Excel.Application')
# excel.Visible =False
# fname = r"E:\python\vscode\pay\급여x1.xlsx"
# # print(fname[:-1])
# wb = excel.Workbooks.Open(fname)
# # wb.Close()
# wb.SaveAs(fname[:-1], FileFormat=56)
# # wb.Close()
# excel.Application.Quit()
https://ybworld.tistory.com/137
[파이썬/업무자동화] win32com.client 사용해서 엑셀 사용하기 기초
* Win32com.client로 엑셀 다루기 포스팅 1편 : 2021.11.23 - [코딩/업무자동화] - [파이썬/업무자동화] win32com.client 사용해서 엑셀 사용하기 기초 2편 : 2021.12.14 - [코딩/업무자동화] - [파이썬/업무자동..
ybworld.tistory.com
'컴퓨터 > Python' 카테고리의 다른 글
pyqt5 qtablewidget to excel (0) | 2022.10.21 |
---|---|
python vba매크로 포함 파일 만들기 (0) | 2022.10.10 |
class101 timepercent 따라하기 (0) | 2022.10.03 |
xlsxwriter dataframe image 넣기 (0) | 2022.09.30 |
python pyside6 QTableWidget excel to excel 다른 엑셀파일 시트 복사하기 (0) | 2022.09.23 |