5

My first question on the site, so hopefully I'm doing this right.

I use file juggler on my windows machine. The program can watch for new files and trigger run commands.

When a new csv file arrives I would like a run command that would open that file in excel.

Thanks

Canadian Luke
  • 24,199
  • 39
  • 117
  • 171
Dean
  • 61
  • 1
  • 1
  • 4

2 Answers2

6

If you include the Office directory that contains Excel.exe, then you don't need to explicitly set the path in your command line. The simplest thing to try is just type excel.exe and the CSV file name after it.

Otherwise, you will have to set the path explicitly. Using double quotes for excel and double quotes for the CSV is best:

"c:\program files\microsoft office\office12\excel.exe" "c:\newfile.csv" 
Sun
  • 6,192
  • 10
  • 34
  • 54
  • Hey Sun, Thank you so much. I had to use the explicit path but it works perfectly! – Dean Mar 17 '14 at 23:37
  • 1
    When loading a CSV file in Excel this way, all the CSV columns fall in Excel's column 'A'. Is there a way, from the command line to indicate what the column separator is? – Hans Deragon Mar 26 '18 at 14:46
  • Question is out of scope. You can try here https://superuser.com/questions/238944/how-to-force-excel-to-open-csv-files-with-data-arranged-in-columns or use Excel macro to activate to process csv as you want – Sun Mar 27 '18 at 18:41
1

You can use Python to open a .csv file in Excel. It will still save as a .csv unless you change the format using Save As:

import os
WK_PATH = "C:\\Working_files\\"
f_name = "myfile"
os.system('start excel ' + WK_PATH + f_name + '.csv')
  • Welcome to Super User. Please read about [properly formatting code](https://superuser.com/help/formatting) in answers. That will also resolve the issue with `\\`. – Worthwelle Aug 07 '20 at 19:50
  • I’m not entirely sure why you’d want to call a Python program which simply executes `start myfile.csv` - you might as well just run that command directly. Plus you’ve not caveated your answer with the note that if you’ve associated `.csv` files to something else then excel won’t run. – Richard Aug 07 '20 at 20:38
  • Thanks for the suggestion. I'm just learning Python now, so it's great to see this as an option. – Dean Aug 10 '20 at 01:56
  • The purpose of opening excel from Python is to pre-process a file, open in excel for an edit, close the file and continue to processing in Python. The double '\\' works for the windows enviornment and translates to a single '\' in the command. – Adam Safier Sep 24 '20 at 22:35