|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
由于工作原因,需要用到Python和Excel的结合。
看到了一下如下的例子,就是简单的Python和Excel连接。
想请教一下Tkinter的用法
- from Tkinter import Tk
- from time import sleep
- from tkMessageBox import showwarning
- import win32com.client as win32
- warn=lambda app:showwarning(app,'Exit?')
- RANGE=range(3,8)
- def excel():
- app='Excel'
- x1=win32.gencache.EnsureDispatch(
- '%s.Application' % app
- )
- ss=x1.Workbooks.Add()
- sh=ss.ActiveSheet
- x1.Visible=True
- sleep(1)
- sh.Cells(1,1).Value='Python-to-%s Demo' % app
- sleep(1)
- for i in RANGE:
- sh.Cells(i,1).Value='Line %d' % i
- sleep(1)
- sh.Cells(i+2,1).Value="Th-th-th-that's all folks!"
- warn(app)
- ss.Close()
- x1.Application.Quit()
- if __name__=='__main__':
- Tk().withdraw()
- excel()
复制代码
求指教 |
|