# encoding: utf-8 from ctypes import * import time import win32com.client as win32 import os cur_dir=os.getcwd() BSFile = [ 'Monster', 'MonsterDynamicProp', 'SkillData', 'NpcData', 'BUFF', 'BattleServerConfig', 'BuffData' ] def get_dir(*pathes): if pathes: return os.path.join(cur_dir, *pathes) return cur_dir def has_dir(path): return True if os.path.isdir(path) else False def transform(parent_path,out_path): print("====parent_path=-====" + parent_path) for path, d, fileList in os.walk(parent_path): num = len(fileList) for i in range(num): file_Name = os.path.splitext(fileList[i]) #文件和格式分开 if file_Name[0] in BSFile and file_Name[1] == '.xml': transfile1 = path+'\\' +fileList[i] #要转换的excel transfile2 = out_path+'\\'+file_Name[0] #转换出来excel excel=win32.gencache.EnsureDispatch('excel.application') pro=excel.Workbooks.Open(transfile1) #打开要转换的excel pro.SaveAs(transfile2+".xlsx", FileFormat=56) #另存为.xlsx格式 pro.Close() excel.Application.Quit() if __name__=='__main__': path1=get_dir("./") #待转换文件所在目录 path2=get_dir("../date_config") #转换文件存放目录 if not has_dir(path2): os.makedirs(path2) transform(path1, path2)