|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 lemon_wb 于 2021-9-25 18:14 编辑
需要讲旧版的xls文件转换为xlsx文件,找到一段代码,运行有错误,不知道是怎么回事,求助~import win32com.client as win32
fname = "C:\\Users\\test\\Desktop\\***.xls"
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(fname)
wb.SaveAs(fname+"x", FileFormat = 51) #FileFormat = 51 is for .xlsx extension
wb.Close() #FileFormat = 56 is for .xls extension
excel.Application.Quit()
报错信息如下:
Traceback (most recent call last):
File "d:/Users/test/PycharmProjects/pythonProject1/333333.py", line 4, in <module>
excel = win32.gencache.EnsureDispatch('Excel.Application')
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\gencache.py", line 531, in EnsureDispatch
mod = EnsureModule(tla[0], tla[1], tla[3], tla[4], bForDemand=bForDemand)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\gencache.py", line 515, in EnsureModule
module = MakeModuleForTypelib(typelibCLSID, lcid, major, minor, progressInstance, bForDemand = bForDemand, bBuildHidden = bBuildHidden)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\gencache.py", line 284, in MakeModuleForTypelib
makepy.GenerateFromTypeLibSpec( (typelibCLSID, lcid, major, minor), progressInstance=progressInstance, bForDemand = bForDemand, bBuildHidden = bBuildHidden)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\makepy.py", line 279, in GenerateFromTypeLibSpec
gen.generate(fileUse, bForDemand)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\genpy.py", line 829, in generate
self.do_generate()
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\genpy.py", line 892, in do_generate
oleItems, enumItems, recordItems, vtableItems = self.BuildOleItemsFromType()
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\genpy.py", line 757, in BuildOleItemsFromType
oleItem, vtableItem = self._Build_Interface(type_info_tuple)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\genpy.py", line 725, in _Build_Interface
oleItem = DispatchItem(info, attr, doc)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\genpy.py", line 274, in __init__
build.DispatchItem.__init__(self, typeinfo, attr, doc)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\build.py", line 119, in __init__
self.Build(typeinfo, attr, bForUser)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\build.py", line 267, in Build
self._AddFunc_(typeinfo,fdesc,bForUser)
File "D:\Users\test\PycharmProjects\pythonProject1\venv\lib\site-packages\win32com\client\build.py", line 156, in _AddFunc_
assert(fdesc.desckind == pythoncom.DESCKIND_FUNCDESC)
AttributeError: 'PyFUNCDESC' object has no attribute 'desckind' |
|