使用Python启动Excel文件 [英] Use Python to launch Excel file
问题描述
当我尝试
os.system("open " + 'myfile.xlsx')
我得到输出'0'
when i try
os.system("open " + 'myfile.xlsx')
i get the output '0'
类似地,尝试
os.system("start excel.exe myfilepath")
给出结果32512
similarly, trying
os.system("start excel.exe myfilepath")
gives the result 32512
我已经导入了操作系统和系统,并且在Mac上.如何更改此设置,以便它确实启动该excel文件?出于好奇,它打印出的数字是什么意思?
I have imported os and system, and I'm on mac. How can I change this so it does actually launch that excel file? And out of curiosity, what do the numbers it prints out mean?
谢谢!
推荐答案
如果只想打开excel应用程序,则可以使用子过程:
If you only want to open the excel application you could use subprocess:
import subprocess
subprocess.check_call(['open', '-a', 'Microsoft Excel'])
您还可以使用os并打开特定文件:
You can also use os and open a specific file:
import os
os.system("open -a 'path/Microsoft Excel.app' 'path/file.xlsx'")
如果您想在python中打开一个excel文件并对其进行修改,则有许多软件包可以用作 xlsxwriter , xlutils 和 openpyxl 我更喜欢后者.
If you on other hand want to open an excel file within python and modify it there's a number of packages to use as xlsxwriter, xlutils and openpyxl where the latter is prefered by me.
另一个说明,如果您使用的是Mac,则excel应用程序不是.exe
Another note, if you're on mac the excel application isn't .exe
这篇关于使用Python启动Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!