2

Is there any way to call an Excel WorksheetFunction in Python win32com or any other libraries?

I would like to use formulas like VLookup/Match/Index/SumIfs in Python.

fuglede
  • 17,388
  • 2
  • 54
  • 99
ReverseEngineer
  • 529
  • 1
  • 5
  • 18

1 Answers1

3

Yes. You can use the WorksheetFunction object on the Application object. For instance, in the particular case of Match, to find the first occurrence of 1.0 in 'B:B' in the first sheet of the first open workbook, you can do

import win32com.client
excel = win32com.client.Dispatch('Excel.Application')
workbook = excel.Workbooks(1)
worksheet = workbook.Worksheets(1)
excel.WorksheetFunction.Match(1.0, worksheet.Range('B:B'), 0)
rwtwm
  • 23
  • 5
fuglede
  • 17,388
  • 2
  • 54
  • 99