반응형
import win32com.client as win32
def xls_to_xlsx(source):
if not str(source).find("xls") > -1:
return
excel = win32.Dispatch("Excel.Application")
# excel = win32.gencache.EnsureDispatch("Excel.Application")
wb = excel.Workbooks.Open(source)
xlsx_file = source + "x"
if os.path.isfile(xlsx_file):
os.remove(xlsx_file)
wb.SaveAs(xlsx_file, FileFormat=51) # FileFormat = 51 is for .xlsx extension
wb.Close() # FileFormat = 56 is for .xls extension
excel.Application.Quit()
def xlsx_to_xls(source):
if not str(source).find("xlsx") > -1:
return
if not os.path.isfile(source):
return
# excel = win32.gencache.EnsureDispatch("Excel.Application")
excel = win32.Dispatch("Excel.Application")
wb = excel.Workbooks.Open(source)
print("xlsx_to_xls")
xls_file = source[:-1]
if os.path.isfile(xls_file):
os.remove(xls_file)
wb.SaveAs(xls_file, FileFormat=56) # FileFormat = 51 is for .xlsx extension
wb.Close() # FileFormat = 56 is for .xls extension
excel.Application.Quit()
os.remove(source)
return xls_file반응형
'프로그래밍 > python' 카테고리의 다른 글
| dataframe에서 값이 일치하는 열이 있는 행을 검색하는 코드 (0) | 2023.05.10 |
|---|---|
| 파이썬 한 폴더 내에 파일명 + 확장자가 포함된 것중 가장 최근 파일 가져오기 (0) | 2023.05.09 |
| 대괄호 안의 문자를 추출하는 함수 (0) | 2023.05.04 |
| pyinstaller icon 깨질때 (0) | 2023.05.04 |
| python에서 dict를 str로 바꾸는 여러가지 방법 (0) | 2023.05.02 |