Questions tagged [win32com]

win32com is a Python module to interact with Windows COM components. It is part of the Python for Win32 (pywin32) project by mhammond.

win32com is a Python module to interact with windows COM components. It is part of the Python for Win32 (pywin32) extensions project by mhammond, which provides access to many of the Windows APIs from Python.

The Python COM package can be used to interface to almost any COM program (such as the MS-Office suite), write servers that can be hosted by any COM client (such as Visual Basic or C++), and has even been used to provide the core ActiveX Scripting Support.

1868 questions
6
votes
5 answers

Add signature to outlook email with python using win32com

Does anyone know how to add an email signature to an email using win32com? import win32com.client as win32 outlook = win32.Dispatch('outlook.application') mail = outlook.CreateItem(0) mail.To = 'TO' mail.Subject = 'SUBJECT' mail.HTMLbody =…
Michael David
  • 93
  • 2
  • 2
  • 7
6
votes
1 answer

How do I search & replace all occurrences of a string in a ms word doc with python?

I am pretty stumped at the moment. Based on Can I use Win32 COM to replace text inside a word document? I was able to code a simple template system that generates word docs out of a template word doc (in Python). My problem is that text in "Text…
Mark
  • 61
  • 3
6
votes
1 answer

How to use win32com.client.constants with MS Word?

Whats wrong with this code? Why win32com.client.constants doesn't have attribute wdWindowStateMinimize? >>> import win32com.client >>> w=win32com.client.Dispatch("Word.Application") >>> w.WindowState =…
ssssergey
  • 253
  • 1
  • 5
  • 9
6
votes
2 answers

How to have win32com code completion in IPython?

Via import win32com.client wordapp = win32com.client.gencache.EnsureDispatch('Word.Application') I can get a Word Application object documented e.g. here. However, ipython's autocompletion is not aware of that API, is there any way to add that?
Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
6
votes
2 answers

How can I Bold only part of a string in an Excel cell with Python?

I'm using win32com to fill out an Excel spreadsheet with some analytic information. I have a cell that I want to be in this form: This is the problem description: this is the command you run to fix it I can't seem to figure out how to get the text…
Derek Chadwell
  • 696
  • 1
  • 8
  • 22
6
votes
3 answers

Writing array to Excel in Python with win32com

I'm making a Python script which parses data files. The parsed data is then sent to an Excel file. The data can be rather huge. I'm looking at 10 to 20 columns, but the number of rows can be well over 100.000. Writing this amount of data to Excel…
Eric
  • 195
  • 1
  • 3
  • 7
6
votes
5 answers

.xlsx and xls(Latest Versions) to pdf using python

With the help of this .doc to pdf using python Link I am trying for excel (.xlsx and xls formats) Following is modified Code for Excel: import os from win32com import client folder = "C:\\Oprance\\Excel\\XlsxWriter-0.5.1" file_type =…
eegloo
  • 1,479
  • 3
  • 17
  • 29
6
votes
1 answer

Python win32com.client.Dispatch looping through Word documents and export to PDF; fails when next loop occurs

Based on the script here: .doc to pdf using python I've got a semi-working script to export .docx files to pdf from C:\Export_to_pdf into a new folder. The problem is that it gets through the first couple of documents and then fails…
James N
  • 603
  • 3
  • 8
  • 18
6
votes
1 answer

How to create a shell extension context menu in Python (like dropbox)

I would like to create a context menu shell extension, to go with a program I write in Python. I tried to work with a the demo in \Lib\site-packages\win32comext\shell\demos\servers\context_menu.py from pywin32 (here is the file) but it didn't work…
zenpoy
  • 19,490
  • 9
  • 60
  • 87
6
votes
1 answer

How to copy a table from excel to word using pythonCOM

Is it possible to get the table from excel file and paste it to the word document saving its excel style? I didn't find adequate documentation about win32com and all its methods. I've found a method PasteExcelTable, and I guess I should select the…
Vladimir
  • 601
  • 2
  • 7
  • 13
5
votes
2 answers

Printing Excel sheets with COM interface

I've programatically made a bunch of Excel sheets with xlwt in python. It's all gone fine, but now I need to convert them all to pdf. I've been trying to do this with pywin32 and the com interface. I can get somewhat close by going like this: import…
Alex S
  • 4,726
  • 7
  • 39
  • 67
5
votes
3 answers

Send Outlook email with attachment to list of users in Excel with python

I am able to send email using outlook with below script, but if I try to send attachment it gives error. File Name_Email.xlsx NAME EMAIL Roy Roy@gmail.com Jack Jack@gmail.com Python Script import win32com.client as win32 import pandas as…
ukki
  • 105
  • 1
  • 9
5
votes
1 answer

Win32 PrintDlg, PrintDlgEx, Crashing and quirkiness

I'm tasked with solving the following issue: My application crashes when running on a 64 bit machine when the PrintDlg() function is called. After digging and hair pulling, I've decided the best solution is to replace the original calls of…
greggorob64
  • 2,487
  • 2
  • 27
  • 55
5
votes
1 answer

Adding Principal.RunLevel to Task Scheduler on Python using win32com

After looking around the internet for many days. I've decided to ask my own question. I've done some digging around and found some ways to implement this but i'm stuck. I know that i have to change the logon_type and set the username but it doesn't…
5
votes
0 answers

outlook pywintypes.com_error when sending an email

The first time I send an email using outlook, it succeeds. Then, in the second loop iteration, it fails import threading import pythoncom # to lauch mails in threads import win32com.client as win32 # pip install pywin32, pip install pypiwin32 from…
vadtam
  • 343
  • 4
  • 15