python - 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() 也放在了那个拉伸之前,什么也没有。
我需要代码来完成这一步来开始格式化整个文件。
解决方案
解决方案!令人惊讶的是:
我无法相信这个错误是如何模糊不清的,我们发现解决方案正在寻找与等效 .NET 代码类似的问题:
要修复它,请在 64 位架构上的“C:\Windows\SysWOW64\config\systemprofile\”或 32 位服务器上的“C:\Windows\System32\config\systemprofile\”下创建一个名为“Desktop”的文件夹。
完美工作。
(来源:StackOverflow 英文回答:excel access denied with win32 python pywin32)
推荐阅读
- arrays - 谷歌图表表格图表数组
- java - 线程“主”java.lang.NoClassDefFoundError 中的异常:akka/util/Helpers$ConfigOps$
- c# - 将二进制转换回图像
- openedge - 创建新记录结果运行错误块
- sql - 带有 Sum 的 Oracle SQL 交叉表
- javascript - 如何在 ReactJS 中访问 json 键?
- python - 如何设置 pyplot 子图的 xticks 和字体属性?
- excel - 在 SAP 中调用回车键
- javascript - 在未定义的值上处理可观察的mergeMap
- c# - 如何重构条件语句中的类似代码?