Opening/running Excel file from python

后端 未结 2 1630
予麋鹿
予麋鹿 2021-01-14 17:24

I need to start excel and open a file directly from python. Currently I am using:

import os
os.system(\'start excel.exe file.xls\')

However

2条回答
  •  难免孤独
    2021-01-14 17:47

    You can also define the directory, where the python should operate.

    import os
    
    os.chdir('C:\\my_folder\\subfolder')
    
    os.system('start excel.exe my_workbook.xlsx')
    
    1. Don't forget to use backslashes in your path and there must be two of them everytime.
    2. my_workbook.xlxs - here will be the name of your file
    3. That file must be in that folder :)

提交回复
热议问题