반응형
import win32com.client as win32
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")
wb = excel.Workbooks.Open(source)
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)
변환에 사용한 .xlsx 파일은 삭제된다.
반응형
'프로그래밍 > python' 카테고리의 다른 글
[selenium] 크롬 드라이버의 기본 설치 경로 변경 (0) | 2022.10.18 |
---|---|
python apscheduler BackgroundScheduler start specific times (0) | 2022.10.13 |
따옴표 안의 문자열을 추출하는 정규식 (0) | 2022.10.07 |
dataframe contains and operation 여러 조건을 만족하는 데이터 필터링 (0) | 2022.10.05 |
문자열에서 숫자만 가져오는 여러 방법 (0) | 2022.09.29 |