从Python自动化Excel [英] Automation Excel from Python
问题描述
我正在考虑使用Python来完成所有这些工作,但是在跳进之前,我需要找到一个可以执行的python包。
- 如果我需要打开Excel,我需要自动完成执行该任务的任务,然后使用python来处理Excel(及其加载项)脚本每天或在一天的特定时刻(市场数据需要提供特定的时间)
感谢您的建议
你需要Python Win32扩展 - http://sourceforge.net/projects/pywin32/
然后你可以使用COM。
$ b $来自win32com.client import的b
调度
excel = Dispatch('Excel.Application')
wb = excel.Workbooks.Open(r'c:\\
ws = wb.Sheets('我的工作表')
#做其他的东西,就像VBA
wb.Close()
excel.Quit()
您可以将脚本放在Windows任务计划程序上,以运行您需要的时间。
In my company, we use Linux in development and production environment. But we have a machine running Windows and Excel because we use a third party application excel addin to get financial market data to the machine. The add-in provides some functions (just like Excel function) for getting these datas into the local machine and then sending back to a MySql Database. We've also developed some VBA script to automation the task but still not satisfy with the result. I'm considering using Python to do all these jobs, but before jumping in, i need to find a python package that can do
- Use python to manipulate Excel (with its add-ins) and use its functions without opening Excel?
- If I need to open Excel, I need to automate that task of executing the script every day, or in specific moment of the day (the market data need to be feed a specific time)
Thanks for suggestion
You'll need the Python Win32 extensions - http://sourceforge.net/projects/pywin32/
Then you can use COM.
from win32com.client import Dispatch
excel = Dispatch('Excel.Application')
wb = excel.Workbooks.Open(r'c:\path\to\file.xlsx')
ws = wb.Sheets('My Sheet')
# do other stuff, just like VBA
wb.Close()
excel.Quit()
You can put your script on Windows Task Scheduler to run for the times you need.
这篇关于从Python自动化Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!