pywin32

python与macro宏调用

随声附和 提交于 2019-12-02 20:59:26
一、简单的宏示例 打开excel 软件,在视图里打到宏功能,创建一个名为Test_Marco 的宏,其代码如下: Sub Test_Macro() MsgBox "This is a macro in Excel" End Sub 二、宏调用 1、vbs 调用宏 windows下本身可以通过vbs 脚本很容易的实现宏的调用,代码如下: Set oExcel = createobject("Excel.Application") oExcel.Visible = false Set oWorkbooks = oExcel.Workbooks.Open("d:/test.xlsm") oExcel.Run "Test_Macro" oWorkbooks.Close oExcel.Quit Set oWorkbooks= nothing Set oExcel= nothing 保存后,右键选择VBS程序打开执行和直接打开excel 后调用的结果是相同的。 2、python调用宏 python 调用宏是利用了win32com模块实现的,具体代码如下: from __future__ import print_function import unittest import os.path import win32com.client class ExcelMacro(unittest

How do I get started with PyWin32 [closed]

纵饮孤独 提交于 2019-12-02 20:33:44
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. I am looking for good resources to get started with pywin32. I haven’t found much in the way of tutorials, books or blogs that talk about it. I’d like to be able to use python to automate some of my common repetitive Microsoft Excel and Word Tasks (such as

ctypes: construct pointer from arbitrary integer

混江龙づ霸主 提交于 2019-12-02 19:05:32
For low-level purposes, I need to construct a ctypes pointer from an arbitrary address, given as an integer. For instance: INTP = ctypes.POINTER(ctypes.c_int) p = INTP(0x12345678) # i *know* this is the address But all such attempts result in TypeError: expected c_long instead of int Is there anything I can do to overcome this? In case someone wonders why I need this, it's done so as to extract the OVERLAPPED struct from a win32file.PyOVERLAPPED , for integrating ctypes-exposed functions with win32file wrapped APIs. Thanks, -Tomer You can use ctypes.cast(addr, type) . I'll extend your example

Creating pivot table in Excel using python

断了今生、忘了曾经 提交于 2019-12-02 17:21:28
I adapted the following code found here to create a pivot table in my existing excel sheet: import win32com.client as win32 win32c = win32.constants import sys import itertools tablecount = itertools.count(1) def addpivot(wb,sourcedata,title,filters=(),columns=(), rows=(),sumvalue=(),sortfield=""): newsheet = wb.Sheets.Add() newsheet.Cells(1,1).Value = title newsheet.Cells(1,1).Font.Size = 16 tname = "PivotTable%d"%tablecount.next() pc = wb.PivotCaches().Add(SourceType=win32c.xlDatabase, SourceData=sourcedata) pt = pc.CreatePivotTable(TableDestination="%s!R4C1"%newsheet.Name, TableName=tname,

SetCursorPos fail with “the parameter is incorrect” after rdp session terminated

大城市里の小女人 提交于 2019-12-02 13:15:25
I have application running on win 2008 server. It is using win32 api and it works just fine when i connected to the server with RDP. When i disconnect every call to SetCursorPos end with this failure. Coordinates (arguments) are same for both cases. Any thoughts ? If RDP is disconnected, it's impossible to do anything with GUI (no screen, no mouse). There are few workarounds though. Keep RDP open (not in a full screen) and switch to another window on local machine (RDP must not be minimized). In this case your script will work, but it's not fully automated solution because turning your local

Unable to get all available networks using WlanGetAvailableNetworkList in Python

ぐ巨炮叔叔 提交于 2019-12-02 10:57:45
问题 I am trying to get the list of all available networks using WlanGetAvailableNetworkList . The scan returns an object which contains NumberOfItems . When I loop over the array of networks based NumberOfItems it only shows me the first network and anything beyond that gives me IndexError: invalid index . here's my code from win32wifi.Win32Wifi import WlanScan, WlanOpenHandle, WlanGetProfileList, WlanEnumInterfaces, WlanGetAvailableNetworkList, WlanCloseHandle, WlanConnect handle =WlanOpenHandle

Reading Table Contet In Header And Footer In MS-Word File Using Python

扶醉桌前 提交于 2019-12-02 10:31:56
问题 This is my extended question for the question: How to read contents of an Table in MS-Word file Using Python? The solution provided by @YusuMishi is great, but it does not catch the headers in the header and footer. Let me elaborate on that: Using the code import win32com.client as win32 import os word = win32.Dispatch("Word.Application") word.Visible = 0 p = os.path.abspath("Catch my tables.docx") word.Documents.Open(p) doc = word.ActiveDocument print doc.Tables.Count I will get 2 printed (

Change printer tray with pywin32

ⅰ亾dé卋堺 提交于 2019-12-02 09:30:35
问题 I'm trying to change the printer tray using the Python win32print module without any success. The printer supports two 'bins': 7=Auto and 4=Manual. I want to start a print job from the 'manual' bin. Here's some code: import win32print import win32gui # Constants from wingdi.h DM_OUT_BUFFER = 0x02 DM_IN_BUFFER = 0x08 DM_IN_PROMPT = 0x04 DM_DEFAULT_SOURCE = 0x200 # Get a handle for the default printer device_name = win32print.GetDefaultPrinter() handle = win32print.OpenPrinter(device_name) #

Change printer tray with pywin32

天涯浪子 提交于 2019-12-02 04:51:08
I'm trying to change the printer tray using the Python win32print module without any success. The printer supports two 'bins': 7=Auto and 4=Manual. I want to start a print job from the 'manual' bin. Here's some code: import win32print import win32gui # Constants from wingdi.h DM_OUT_BUFFER = 0x02 DM_IN_BUFFER = 0x08 DM_IN_PROMPT = 0x04 DM_DEFAULT_SOURCE = 0x200 # Get a handle for the default printer device_name = win32print.GetDefaultPrinter() handle = win32print.OpenPrinter(device_name) # Get the default properties for the printer properties = win32print.GetPrinter(handle, 2) devmode =

Reading Table Contet In Header And Footer In MS-Word File Using Python

淺唱寂寞╮ 提交于 2019-12-02 04:15:16
This is my extended question for the question: How to read contents of an Table in MS-Word file Using Python? The solution provided by @YusuMishi is great, but it does not catch the headers in the header and footer. Let me elaborate on that: Using the code import win32com.client as win32 import os word = win32.Dispatch("Word.Application") word.Visible = 0 p = os.path.abspath("Catch my tables.docx") word.Documents.Open(p) doc = word.ActiveDocument print doc.Tables.Count I will get 2 printed ( Table 1 and Table 2 ) How do I go through the information in Table 0 and Table N Get the document here