首页 > 解决方案 > win32com的问题

问题描述

我的代码中有以下错误,我已经尝试了所有方法,但无法解决:

1° 不成功

excel = win32com.client.Dispatch("Excel.Application")
wb = excel.Workbooks.Open(os.path.join(os.getcwd(),diretorio_BKP + filename +
                          '  '+str(nome_arq_parcial)+' -.xlsx'))
ws = wb.Worksheets(1).Select()
ws = wb.Worksheets(1)
print('abrir o arquivo de novo')

2° 不成功

excel = win32com.client.Dispatch("Excel.Application")
wb = excel.Workbooks.Open(diretorio_BKP + filename +'  '+
                          str(nome_arq_parcial)+' -.xlsx')
ws = wb.Worksheets(1).Select()
ws = wb.Worksheets(1)
print('abrir o arquivo de novo')

这两次尝试将以下问题返回给我:

ERRO:    (-2147352567, 'Exception.', (0, 'Microsoft Excel', "Microsoft Excel does not you can access the file '\\\\ IEMEN \\ file location -.xlsx'. There are several reasons possible: \ r \ n \ r \ n • The file name or path does not exist. \ r \ n • The file is being used by another program. \ r \ n • The workbook you are trying to save has the same name as another currently open \ r \ nfolder. ", 'xlmain11.chm', 0, -2146827284), None)

正如您所看到的,已经尝试离开绝对路径,已经尝试离开完整路径,我已经将 excel.Application.Quit() 也放在了那个拉伸之前,什么也没有。

我需要代码来完成这一步来开始格式化整个文件。

标签: pythonpython-3.xwin32com

解决方案


解决方案!令人惊讶的是:

我无法相信这个错误是如何模糊不清的,我们发现解决方案正在寻找与等效 .NET 代码类似的问题:

要修复它,请在 64 位架构上的“C:\Windows\SysWOW64\config\systemprofile\”或 32 位服务器上的“C:\Windows\System32\config\systemprofile\”下创建一个名为“Desktop”的文件夹。

完美工作。

(来源:StackOverflow 英文回答:excel access denied with win32 python pywin32


推荐阅读