Is there something like pywin32 in Julia?

Is there something like pywin32 in Julia?
I want to use the stmafm ole/com interface.

PyCall could work, but I am curious if there is a Julia native option.

You can already use ccall to natively access the Win32 API in Julia.

This is used extensively in the Julia standard library. See, for example, how tempname is implemented for Windows.

Of course, if you are using Win32 APIs extensively, you might want higher-level wrappers on top of the Win32 API. AFAIK there has been no systematic effort to provide this — people usually just ccall at need. (One generally tries to keep such code to a minimum in most Julia packages, in order to keep things platform-independent.)

1 Like

Here is my example to use PyCall to open and modify an existing Excel-file via a COM server:

# Create COM server via Python Interface
# first: install "pywin32" via conda:
# using Conda; Conda.add("pywin32")

using PyCall
using XLSX
pw = pyimport("win32com")
pwc = pyimport("win32com.client")


FN_excel = raw"C:\tmp\MyTest.xlsx";
if ~isfile(FN_excel)
    XLSX.writetable(FN_excel)
end

xlApp = pwc.Dispatch("Excel.Application")
xlApp.Visible = 1
if isfile(FN_excel)
    workBook = xlApp.Workbooks.Open(FN_excel)
else
    error("file \"" * FN_excel * "\" does not exist!\n")
end
workBook.ActiveSheet.Cells(1, 1).Value = "hello world"
workBook.Close(SaveChanges = 1)
xlApp.Quit()

I hope it helps others to get started.

3 Likes