Anasayfa / python / python xls to xlsx converter windows

python xls to xlsx converter windows

def get_list_files_in_folders(path: str, file_ext: str = ''):
    """
    directory deki ve sub directory deki dosyalarin listesini doner
    """
    tmp_list = []
    for root, dirs, files in os.walk(path):
        for file in files:
            if file.endswith(file_ext):
                tmp_list.append(os.path.join(root, file))
                # print(os.path.join(root, file))

    return tmp_list
def get_file_name_from_path(path: str):
    return os.path.basename(path)
import os
import win32com.client as win32
from utils_path import get_list_files_in_folders, get_file_name_from_path

BASEDIR = os.path.abspath(os.path.dirname(__file__))
xls_folder = BASEDIR + os.sep + 'xls'
xlsx_folder = xls_folder + 'x'

def main():
    xls_file_list = get_list_files_in_folders(xls_folder)
    cnt = len(xls_file_list)
    print ('Excel xlsx çevirme işlemi başlıyor..')
    print ('Toplam Excel dosya sayısı : ', cnt)
    for i, xls_file in enumerate(xls_file_list):
        excel = win32.gencache.EnsureDispatch('Excel.Application')
        wb = excel.Workbooks.Open(xls_file)
        save_name = xlsx_folder + os.sep + get_file_name_from_path(xls_file) + 'x'
        wb.SaveAs(save_name, FileFormat = 51)    #FileFormat = 51 is for .xlsx extension
        wb.Close()                               #FileFormat = 56 is for .xls extension
        excel.Application.Quit()
        print('\r ', i, ' / ', cnt, xls_file,  ' -> ', save_name ,end ='')

if __name__ == '__main__':
    main()

 

Hakkında ibrahim

İlgili Makaleler

python base dir

BASEDIR = os.path.abspath(os.path.dirname(__file__))  

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir