Search code examples
pythonwin32comxlwingspythoncom

From python numpy array or list to COM SAFEARRAY


Is there any built in method or any other way to translate a python numpy array/list to COM SAFEARRAY?

There is a similar method in R: R Matrix to COMSAFEARRAY

Quite weirdly I have not found anything in python.

I want to use it in order to pass an array into a VBA function which I call from python.

Thank you


Solution

  • xlwings takes care of this:

    import xlwings as xw
    import numpy as np
    
    book = xw.Book()
    book.sheets[0]['A1'].value = np.array([[1, 2], [3, 4]])