- # Filename: excel.py
- import os,sys,time
- import win32com.client
- import traceback
- excel = win32com.client.Dispatch("Excel.Application")
- filename = "D://test.xls"
- try:
- d1 = excel.Workbooks.Add()
- sheet = d1.Sheets(1)
- for i in xrange(1,10):
- for j in xrange(1,10):
- sheet.Cells(i,j).Value = str(i*j)
- d1.SaveAs(filename)
- except Exception, e:
- print traceback.print_exc()
- print e
- excel.Quit()