python - 如何在 Python 中打开 Microsoft Excel 中的 csv 文件?

标签 python windows excel scripting automation

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/

相关文章:

python - KafkaError Unsupported compression codec 0x3 with Confluent Python Kafka consumer

python - Selenium 使用 Firefox 配置文件

python - 将字符串转换为有效的 url 内容

python - os.system 在 raw_input() 和 file.readlines() 中的输入表现不同

c - 以编程方式查找单词含义并将其打印到文件

ruby - 无法加载这样的文件——ruby-wmi (LoadError) & 无法加载这样的文件——win32/service (LoadError)

windows - 在不同模块中 Access VBA Form Private Sub 调用 Public Function

python - 如何用 pandas 编写 multiIndex-columns excel

C# 互操作 : excel process not exiting after adding new worksheet to existing file

vba - excel vba中出现错误 “Out of Memory”