Automation Excel from Python

强颜欢笑 提交于 2019-11-27 23:09:47
pyrospade

You'll need the Python Win32 extensions - http://sourceforge.net/projects/pywin32/

(now migrated to GitHub: https://github.com/mhammond/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.

As an alternative, you might consider openpyxl.

import openpyxl
wb= openpyxl.Workbook()
ws = wb.get_active_sheet()
ws.title = 'My Title'
wb.save('C:\\Development\\Python\\alpha.xlsx')

Here's a chapter from the book I'm working through.

https://automatetheboringstuff.com/chapter12/

Luck

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!