Use Python to launch Excel file

后端 未结 5 1416
日久生厌
日久生厌 2020-12-18 04:58

when i try os.system(\"open \" + \'myfile.xlsx\')
i get the output \'0\'

similarly, trying
os.system(\"start excel.exe myfil

5条回答
  •  粉色の甜心
    2020-12-18 05:18

    On Windows 10, this works for me:

    import os
    full_path_to_file = "C:\blah\blah\filename.xlsx"
    os.system(full_path_to_file)
    

    Copy-pasting any full path to a file in the command prompt (or passing it to os.system()) seems to work as long as you have permission to open the file. I suppose this only works when Excel is selected as default application for the .xlsx extention.

提交回复
热议问题