EXCEL 写入

  1. #!/usr/bin/env python
  2. from Tkinter import Tk
  3. from time import sleep
  4. from tkMessageBox import showwarning
  5. import win32com.client as win32
  6. warn = lambda app: showwarning(app, 'Exit?')
  7. RANGE = range(3, 8)
  8. def excel():
  9. app = 'Excel'
  10. xl = win32.gencache.EnsureDispatch('%s.Application' % app)
  11. ss = xl.Workbooks.Add()
  12. sh = ss.ActiveSheet
  13. xl.Visible = True
  14. sh.Cells(1,1).Value = 'Python-to-%s Demo' % app
  15. for i in RANGE:
  16. sh.Cells(i,1).Value = 'Line %d' % i
  17. sh.Cells(i+2,1).Value = "Th-th-th-that's all folks!"
  18. warn(app)
  19. ss.Close(False)
  20. xl.Application.Quit()
  21. if __name__=='__main__':
  22. Tk().withdraw()
  23. excel()





posted @ 2015-02-06 16:22  阳光树林  阅读(156)  评论(0编辑  收藏  举报