简体   繁体   中英

ImporError: No module named 'win32com' Python 3.4

Trying to execute an Excels macro from Python using this code:

import os, os.path
import win32com.client
if os.path.exists("ihm.xlsm"):
    xl = win32com.client.Dispatch("Excel.Application")
    xl.Workbooks.Open(os.path.abspath("ihm.xlsm"))
    xl.Application.Run("ihm.xlsm!Module20.import_utilisateur_encours")
    xl.Application.Save()  # to save uncomment and delete the ", ReadOnly=1" part from the open function.
    xl.Application.Quit()  # Comment this out if your excel script closes
del xl

ImportError: No module named 'win32com'

Already tried to pip install pypiwin32 but I had to specify --no-dependencies and it's still not working. I seen that there are some troubles about win32 module with python 3.4.

I also found a forge .exe with multiple builds, but I cannot run it thanks to security restrictions in my office.

Please Help.

尝试安装pywin32

pip install pywin32

Have you looked into xlwings? That will do what you need it to do and has a simpler interface.

import xlwings as xw
app = xw.App()
macro_result = app.macro('macro_name')

docs are here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM