How to open a csv file in Microsoft Excel in Python?

automation, excel, python, scripting, windows

Solution

Usually on Windows the `.csv` filetype is configured to be opened by Excel. In this case you can just do:

from subprocess import Popen
p = Popen('filename.csv', shell=True)

In case it does not work, try pointing the full path of the Excel application:

subprocess.Popen(r'C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE stack.csv')

Problem

``` base_path = os.path.dirname(os.path.abspath(__file__)) _csvFilename = os.path.join(base_path, "bcForecasting.csv") _csvFile = open (_csvFilename, 'wb') _csvFile = csv.writer(_csvFile, quoting=csv.QUOTE_ALL) _Header = self.makeIntoList (self.root.tss.series () [0].getAllTimes (), self.originalTimesteps + _futurePeriods) _csvFile.writerow (_Header) ``` Now I want to open the created `bcForecasting.csv` file in Excel. How to do it in Python?

Original source

Related problems