win32com

How can I get the text by color from a word document with win32com?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 03:45:08
问题 I have a word document with several tables. In each table there are two colors, black and red. I'd like to get the text from cells in a word document table by its color. I found a way, but I think it's very inefficient. The following code gets the text from a word table cell, and prints each word with it's color. import os, sys import win32com.client, re path = os.path.join(os.getcwd(),"../files/tests2.docx") word = win32com.client.Dispatch("Word.Application") word.Visible = 1 doc=word

Passing additional arguments to python callback object (win32com.client.dispatchWithEvents)

随声附和 提交于 2019-12-20 01:58:18
问题 I am struggling with callback objects, I am a newbie please be nice: I am using the win32com package to interact with a windows application (The application is not important). In short what I am trying to achieve is a subscription to a table that updates. I have successfully implemented a callback that receives the returned data on an update to the table but what I need now is to act on the data received. This problem would be very easy to solve if I could instantiate the callback object with

How to detect Windows is locked?

扶醉桌前 提交于 2019-12-19 06:57:21
问题 How to detect Windows is locked (Win+L or locked by screensaver)? Is it possible? 回答1: There is no documented way to check if the session is locked. There is however a way to detect that the session is getting locked. Use WTSRegisterSessionNotification(), you'll get a WM_WTSSESSION_CHANGE message with the WTS_SESSION_LOCK value when the workstation is being locked. If you are planning to do this from a service then be sure to google "session 0 isolation" to find out why that doesn't work. 来源:

Outlook using python win32com to iterate subfolders

你离开我真会死。 提交于 2019-12-19 05:59:26
问题 I have the following code which gets me the inbox of my shared folder, and all of the emails inside. This code works great and will print the subject of the last email. outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") recip = outlook.CreateRecipient("foo@bar.com") inbox = outlook.GetSharedDefaultFolder(recip, 6) messages = inbox.Items message = messages.GetLast() print (message.Subject) I can access other parent folders in foo@bar.com's mailbox (like Sent), but I

How to get code-completion for COM programming in PyCharm?

柔情痞子 提交于 2019-12-19 04:00:20
问题 When using app = win32com.client.Dispatch('Some.Application') , is there any feasible way get code-completion in PyCharm? It is rather tedious having to retype (or copy-paste) everything from an API documentation, so would creating skeletons be. Is there no other way to let PyCharm know about the Interface provided via COM, especially if I can provide a .tlb file? Or is there at least some way automatically generate such a skeleton (or a wrapping module?) from the TypeLib? 回答1: Since there is

How to use python win32com to save as excel file

随声附和 提交于 2019-12-19 03:36:57
问题 I have a small python code to open an Excel file. Now I want to "Save As" with a different name but same format. How do I do that.. Any help will be great. FK 回答1: Here is a tutorial on using the win32com API with Excel and here is the COM method you will likely have to call, Workbook.SaveAs. And here is an example of actually making the call. 来源: https://stackoverflow.com/questions/1742471/how-to-use-python-win32com-to-save-as-excel-file

Python read my outlook email mailbox and parse messages [duplicate]

半世苍凉 提交于 2019-12-18 10:57:08
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Reading e-mails from Outlook with Python through MAPI I am completely new to Python and have been given the task to write a program that connects to my Microsoft Outlook mailbox, goes through all the emails and if the subject has a certain word, then the details of the email time and subject will be saved in variables, as well as the email message body will be parsed and relevant information will be stored in

Can't close Excel completely using win32com on Python

本秂侑毒 提交于 2019-12-18 10:35:48
问题 This is my code, and I found many answers for VBA, .NET framework and is pretty strange. When I execute this, Excel closes. from win32com.client import DispatchEx excel = DispatchEx('Excel.Application') wbs = excel.Workbooks wbs.Close() excel.Quit() wbs = None excel = None # <-- Excel Closes here But when I do the following, it does not close. excel = DispatchEx('Excel.Application') wbs = excel.Workbooks wb = wbs.Open('D:\\Xaguar\\A1.xlsm') wb.Close(False) wbs.Close() excel.Quit() wb = None

Asynchronous data through Bloomberg's new data API (COM v3) with Python?

南楼画角 提交于 2019-12-18 10:26:41
问题 Does anyone know how to get asynchronous data through Bloomberg's new data API (COM v3) with Python? I found this code below on wilmott.com and it works just fine, but it's for the old API version. Does anyone know the corresponding code for the new version? from win32com.client import DispatchWithEvents from pythoncom import PumpWaitingMessages, Empty, Missing from time import time class BBCommEvent: def OnData(self, Security, cookie, Fields, Data, Status): print 'OnData: ' + `Data` def

How to continuously monitor a new mail in outlook and unread mails of a specific folder in python

本秂侑毒 提交于 2019-12-18 07:13:07
问题 I want to check for a particular sender email and process it automatically wherever it arrives However, there may be some situation where my outlook was restarted, mean while i received mail from sender and marked as unread For continuous monitor for a new mail for a specific subject i have found the following code import win32com.client import pythoncom import re class Handler_Class(object): def OnNewMailEx(self, receivedItemsIDs): # RecrivedItemIDs is a collection of mail IDs separated by a