【发布时间】:2017-12-04 15:58:00
【问题描述】:
我只有很少的代码可以在 Excel 电子表格中打开文件
filename = filedialog.askopenfilename(initialdir="C:/", title="select file",
filetypes=(("excel files", "*.xls"), ("all files", "*.*")))
os.system(r"excel.exe" + filename)
当我选择要读取的文件时,我收到以下错误:
excel.exeC:' 未被识别为内部或外部命令, 可运行的程序或批处理文件。
我尝试使用带有os.system(r"notepad.exe" + filename) 的记事本打开它,但我想使用 excel 在 excel 中打开它。
我欢迎您提出用 excel 文件打开它的建议。
【问题讨论】:
-
不应该只打开文件,在机器默认程序中打开文件?
-
另外 - 尝试用你的 os.system 函数替换它:
subprocess.Popen(["excel.exe", fileName]) -
@Goralight 它尝试了它没有打开的子进程。
-
os.system(r"excel.exe"+filename")会产生类似os.system(r"excel.exec:/some/file.xls")的结果,这几乎就是错误消息告诉您的内容。 -
如何在您的
os.system(r"excel.exe" + filename)呼叫中的“excel.exe”之后添加一个空格...您需要这样才能让操作系统有机会了解您要询问的内容做...