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 实现?
最佳答案
通常在 Windows 上,.csv
文件类型被配置为由 Excel 打开。在这种情况下,您可以这样做:
from subprocess import Popen
p = Popen('filename.csv', shell=True)
如果它不起作用,请尝试指向 Excel 应用程序的完整路径:
subprocess.Popen(r'C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE stack.csv')
关于python - 如何在 Python 中打开 Microsoft Excel 中的 csv 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18173965/