python 生成 ppt word outmail excel
2017-10-21 16:04
465 查看
# coding:utf-8 from Tkinter import Tk from time import sleep from tkMessageBox import showwarning import win32com.client as win32 from time import sleep, ctime from urllib import urlopen warn = lambda app: showwarning(app, 'Exit?') RANGE = range(3, 10) def excel(): s='''I wasn't really shot with a silver bullet.''' sss = s.split() app = 'Excel' xl = win32.gencache.EnsureDispatch('%s.Application' % app) ss = xl.Workbooks.Add() sh = ss.ActiveSheet xl.Visible = True sleep(0.5) sh.Cells(1, 1).Value = 'Python-to-%s Demo' % app sleep(0.5) ii = 2 for i in sss: print i sh.Cells(ii, 1).Value = i ii += 1 sleep(0.5) sh.Cells(ii+2, 1).Value = "xixihahaha" warn(app) ss.Close(False) xl.Application.Quit() def word(): app = 'Word' word = win32.gencache.EnsureDispatch('%s.Application' % app) doc = word.Documents.Add() word.Visible = True sleep(1) rng = doc.Range(0, 0) rng.InsertAfter('Python-to-%s Test\r\n\r\n' % app) sleep(1) for i in range(3, 8): rng.InsertAfter('Line %d\r\n' % i) sleep(1) rng.InsertAfter('\r\nTh-th-th-thats all folks!') warn(app) doc.Close(False) word.Application.Quit() def ppoint(): app = 'PowerPoint' ppoint = win32.gencache.EnsureDispatch('%s.Application' % app) pres = ppoint.Presentations.Add() ppoint.Visible = True s1 = pres.Slides.Add(1, win32.constants.ppLayoutText) sleep(1) s1a = s1.Shapes[0].TextFrame.TextRange s1a.Text = 'Python-to-%s Test\r\n\r\n' % app sleep(1) s1b = s1.Shapes[1].TextFrame.TextRange for i in range(3, 8): s1b.InsertAfter('Line %d\r\n' % i) sleep(1) s1b.InsertAfter("\r\nTh-th-th-thats all folks!") warn(app) pres.Close(False) ppoint.Quit() def outlook(): app = 'Outlook' olook = win32.gencache.EnsureDispatch('%s.Application' % app) mail = olook.CreateItem(win32.constants.olMailItem) recip = mail.Recipients.Add('815467444@qq.com') subj = mail.Subject = 'Python windows program demo with outlook\n' body = ['Line %d' % i for i in RANGE] body.insert(0, '%s\r\n' % subj) body.append("\r\nTh-th-th-that's all folks!") mail.Body = '\r\n'.join(body) mail.Send() ns = olook.GetNamespace("MAPI") obox = ns.GetDefaultFolder(win32.constants.olFolderOutbox) obox.Display() obox.Items.Item(1).Display() warn(app) olook.Quit() TICKS = ('BABA', 'GOOG', 'EBAY', 'AMZN') COLS = ('TICKER', 'PRICE', 'CHG', '%AGE') URL = 'http://quote.yahoo.com/d/quotes.csv?s=%s&f=sl1c1p2' def excell(): app = 'Excel' xl = win32.gencache.EnsureDispatch('%s.Application' % app) ss = xl.Workbooks.Add() sh = ss.ActiveSheet xl.Visible = True sleep(1) sh.Cells(1, 1).Value = 'PYTHON-to-%s Stock quote demo' % app sleep(1) sh.Cells(3, 1).Value = 'Prices quoted as of: %s' % ctime() sleep(1) for i in range(4): sh.Cells(5, i+1).Value = COLS[i] sleep(1) sh.Range(sh.Cells(5, 1), sh.Cells(5, 4)).Font.Bold = True sleep(1) row = 6 u = urlopen(URL % ','.join(TICKS)) for data in u: tick, price, chg, per = data.split(',') sh.Cells(row, 1).Value = eval(tick) sh.Cells(row, 2).Value = ('%.2f' % round(float(price), 2)) sh.Cells(row, 3).Value = chg sh.Cells(row, 4).Value = eval(per.rstrip()) row += 1 sleep(1) u.close() warn(app) ss.Close(False) xl.Application.Quit() if __name__ == '__main__': Tk().withdraw() excell() #excel() #word() #ppoint() # for i in range(20): # outlook() # sleep(5) # print i
相关文章推荐
- Python 操作Word(Excel、PPT等通用)
- Python 操作Word(Excel、PPT等通用)
- python启动办公软件进程(word、excel、ppt、以及wps的et、wps、wpp)
- Python 操作Word(Excel、PPT等通用)
- Python 操作Word(Excel、PPT等通用)
- Python 操作Word(Excel、PPT等通用)
- 用java把MS office(ppt、excel、word、txt) 转换成 flash,并进行播放(linux、windows)
- 浏览器预览Excel、PPT、Word
- gridview 打开word/excel 生成/另存为word/excel
- 类似百度文库在线预览文档flash版(支持word、excel、ppt、pdf)+在线预览文档html版
- office 文件 (Word / excel / ppt / access) 文件修复
- Spire.Office for .NET(Word、Excel、PPT、PDF等)
- PDF免费转Word、PPT、Excel
- php office文件(word/excel/ppt)转pdf文件
- ASP+模板生成Word、Excel、html
- android Intent 默认打开打开各种类型文件((PDF、word、excel、ppt、chm)
- 用python从一个单词列表中快速生成word_to_ix字典
- Android应用内展示word、excel、pdf、ppt等文件(讯的Tbs)
- Word.Excel.ppt转html