Excel中打开csv文件

Excel中打开csv文件

本文介绍了如何在Python中的Microsoft Excel中打开csv文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)

现在,我想在Excel中打开创建的bcForecasting.csv文件.如何在Python中执行此操作?

Now I want to open the created bcForecasting.csv file in Excel. How to do it in Python?

推荐答案

通常在Windows上,.csv文件类型被配置为由Excel打开.在这种情况下,您可以执行以下操作:

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)

如果它不起作用,请尝试指向Excel应用程序的完整路径:

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')

这篇关于如何在Python中的Microsoft Excel中打开csv文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 22:53