Need A script to open a excel file and extract the data using autofilter

David Monaghan monaghand.david at gmail.com
Sat Oct 1 19:38:01 EDT 2011


On Sat, 01 Oct 2011 23:00:07 +0100, David Monaghan
<monaghand.david at gmail.com> wrote:

>from win32com.client import Dispatch
>xlApp = Dispatch("Excel.Application")
>xlWbook = xlApp.Workbooks.Open(r"C:\Users\Administrator\Desktop\test.xls")
>xlApp.Visible = 1
>xlWorksheet = xlWbook.Worksheets(1)
>xlWorksheet.Columns("A:V").Select() 
>xlApp.Selection.AutoFilter( 2, "pass") # column number, filter criteria
>xlApp.Selection.AutoFilter( 3, "pass")
>xlApp.Selection.AutoFilter( 4, "pass")
>xlApp.Selection.AutoFilter( 5, "pass")
>#etc, etc - up to column 22 in this case
>xlApp.Selection.Copy()

Or rather:

from win32com.client import Dispatch
xlApp = Dispatch("Excel.Application")
xlWbook = xlApp.Workbooks.Open(r'C:\Users\Administrator\Desktop\test.xls')
xlApp.Visible = 1
xlWorksheet = xlWbook.Worksheets(1)
xlWorksheet.Columns("A:V").Select()
for column in range(2,23):
    xlApp.Selection.AutoFilter(column, "pass") 
xlApp.Selection.Copy()



More information about the Python-list mailing list