Forum Discussion

Mr_Bro's avatar
Mr_Bro
Champion Level 0
5 years ago
Solved

Python Module - ImportError No module named win32api

Hi Tem, 

im trying to create a Excel workBook and sheets using Python and im getting error as

"Python runtime error.
ModuleNotFoundError: No module named 'win32api'"
can anyone help me how to resolve the same.
thanks in advance.
from os import sys
sys.path.insert(0, r'C:\Users\sathishkumark\AppData\Local\Programs\Python\Python37\Lib\site-packages')
import win32com
def excelTest():
  Excel = win32com.client.DispatchEx('Excel.Application')
  Book = Excel.Workbooks.Add()
  Excel.Visible = True
  Book.Worksheets(3).Delete()
  Book.Worksheets(2).Delete()
  Sheet = Book.Worksheets(1)
  Sheet.Name = "Summary"
  Book.Worksheets.Add(After=Sheet)
  Sheet = Book.Worksheets(2)
  Sheet.Name = "Data1"

Kind Regards,

Sathish Kumar K

  • It might have to do with the version of Python.  TestComplete uses a separate Python installation and I believe it's using a different version.

     

    However... you really don't need win32com for what you're doing

     

    Sys.OleObject('Excel.Application') will return the Excel application object without having to utilize any outside modules.

1 Reply

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    It might have to do with the version of Python.  TestComplete uses a separate Python installation and I believe it's using a different version.

     

    However... you really don't need win32com for what you're doing

     

    Sys.OleObject('Excel.Application') will return the Excel application object without having to utilize any outside modules.