python - Python word 客户端找不到 .dotx
问题描述
Python 目前无法找到我的文件。
import os
import win32com.client
word=win32com.client.Dispatch("Word.Application")
word.Documents.Open('Test_template')
我越来越'Sorry we can't find your file'
。
当我跑
import os
print(os.listdir('.'))
我可以看到'Test_template.dotx'
。
当我改变
word.Documents.Open('Test_template')
至
word.Documents.Open('Test_template.dotx')
我犯了同样的错误
解决方案
我没有看到此处指定的目录(尽管 os.listdir() 返回该项目的事实似乎令人鼓舞),但请尝试指定完整的目录路径,如下所示:
word.Documents.Open('//folder_1/folder_2/Test_template.dotx')
# You could also specify the working directory explicitly with os, as in:
os.chdir('//folder_1/folder_2')
并仔细检查文件名是否完全匹配——我肯定用一个应该是小写字母而不是大写字母的字母遇到了这些错误。
推荐阅读
- javascript - 如何在 Electron.js 中最小化和最大化?
- notepad++ - 在 Notepad++ 中搜索字符串和换行符
- java - 如何在 Spring Boot 上设置不安全的连接?
- python - 根据熊猫中另一个选项卡中的匹配更改值
- mysql - 如何在 mySQL 工作台中创建函数
- node.js - 有没有在node js的socket程序中连接客户端和服务器的解决方案
- groovy - Groovy - 循环通过 JSON 对象并将值填充为单行
- spring-boot - Spring Boot中应用属性优先级顺序的观察
- python-3.x - 如何在自定义函数中使用字典从大型数据框中计算新列?
- c# - 字典/列表对象的 C# 多态 JSON 反序列化