利用win32库来实现

# -*- coding:utf-8 -*-
import os
import win32com.client as win32

#需要转换的数据目录
inputdir = u'D:\\python\\testdata\\excle'
outputdir = u'D:\\python\\testdata\\excle_output'
if not os.path.exists(outputdir):
    os.mkdir(outputdir)

# 三个参数:父目录;所有文件夹名(不含路径);所有文件名
for parent, dirnames, filenames in os.walk(inputdir):
    for fn in filenames:
        fn.split('.')[-1] == 'xls':
            filedir = os.path.join(parent, fn)

            excel = win32.gencache.EnsureDispatch('Excel.Application')
            wb = excel.Workbooks.Open(filedir)
            # xlsx: FileFormat=51
            # xls:  FileFormat=56
            wb.SaveAs((os.path.join(outputdir, fn + "x")), FileFormat=51)
            wb.Close()
            excel.Application.Quit()

相关文章:

  • 2022-01-09
  • 2023-02-16
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-12-02
  • 2021-11-15
猜你喜欢
  • 2022-12-23
  • 2021-05-25
  • 2022-01-11
  • 2021-10-22
  • 2022-01-28
  • 2021-06-18
  • 2021-06-27
相关资源
相似解决方案