Excel Manipulation using Python

Krishna manthra.mohan at gmail.com
Fri Apr 18 11:21:48 EDT 2008


I was trying to delete rows in an existing .xls file using python. How
do I do that? I was using the following code, it seem to work if I
type in python window, but if I save it in text editor and drage and
drop the .py file, it doesnt work. What am I doing wrong here?  Thanks
for your help!

import win32com.client
from time import sleep
excel = win32com.client.Dispatch("Excel.Application")

def Extract():
 	excel.Visible = 0
	workbook=excel.Workbooks.Open('C:\Trial.xls')

	i=1
	for n in range(1,10):
		excel.Rows(i).Select
		excel.Selection.Delete
		excel.Selection.Delete
		i=i+2
		workbook.Save()
		print "saved"

	excel.Quit()



More information about the Python-list mailing list