import win32com.client 将xls改成xlsx,操作excel报错
一:代码如下:
excel = win32com.client.DispatchEx(‘Excel.Application’)
excel = win32com.client.gencache.EnsureDispatch(‘Excel.Application’
excel = win32com.client.EnsureDispatch(‘Excel.Application’)
excel = win32com.client.gencache.DispatchEx(‘Excel.Application’)
二:报错语句如下:
1、TypeError: This COM object can not automate the makepy process - please run makepy manually for this object
2、AttributeError: module ‘win32com.client’ has no attribute ‘client’(修改代码后一直报缺失win32的某个属性)
3、AttributeError: module ‘win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9’ has no attribute ‘CLSIDToClassMap’
需要将AppData\Local\Temp\gen_py 这个路径下的00020813-0000-0000-C000-000000000046x0x1x9文件删除,然后在运行代码
excel = win32com.client.DispatchEx(‘Excel.Application’)
运行成功