Use the pywin32 module to COM operate Excel and exchange data. Specifically, it looks like the image below.
If you just want to transfer data, you can do it as follows.
import numpy as np
import win32com.client as wc
my_app = wc.GetActiveObject("Excel.Application")
my_sheet = my_app.activesheet
A = np.array(my_sheet.Range("A1:C3").Value)
my_sheet.Range("A5:C7").Value= np.linalg.inv(A).tolist()
When you're done, "my_app = None".
Difficult to use normally. I thought it would be a little more convenient if I wrote an extension of Jupyter ... Especially, it is painful that Excel undo does not work. In this case, it is more convenient to export xlsx normally. Moreover, COM is penalized. I couldn't keep up with the behavior of the property with arguments and threw it out.
Recommended Posts