xml2xlsx.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # encoding: utf-8
  2. from ctypes import *
  3. import time
  4. import win32com.client as win32
  5. import os
  6. cur_dir=os.getcwd()
  7. BSFile = [
  8. 'Monster',
  9. 'MonsterDynamicProp',
  10. 'SkillData',
  11. 'NpcData',
  12. 'BUFF',
  13. 'BattleServerConfig',
  14. 'BuffData'
  15. ]
  16. def get_dir(*pathes):
  17. if pathes:
  18. return os.path.join(cur_dir, *pathes)
  19. return cur_dir
  20. def has_dir(path):
  21. return True if os.path.isdir(path) else False
  22. def transform(parent_path,out_path):
  23. print("====parent_path=-====" + parent_path)
  24. for path, d, fileList in os.walk(parent_path):
  25. num = len(fileList)
  26. for i in range(num):
  27. file_Name = os.path.splitext(fileList[i]) #文件和格式分开
  28. if file_Name[0] in BSFile and file_Name[1] == '.xml':
  29. transfile1 = path+'\\' +fileList[i] #要转换的excel
  30. transfile2 = out_path+'\\'+file_Name[0] #转换出来excel
  31. excel=win32.gencache.EnsureDispatch('excel.application')
  32. pro=excel.Workbooks.Open(transfile1) #打开要转换的excel
  33. pro.SaveAs(transfile2+".xlsx", FileFormat=56) #另存为.xlsx格式
  34. pro.Close()
  35. excel.Application.Quit()
  36. if __name__=='__main__':
  37. path1=get_dir("./") #待转换文件所在目录
  38. path2=get_dir("../date_config") #转换文件存放目录
  39. if not has_dir(path2):
  40. os.makedirs(path2)
  41. transform(path1, path2)