[PYTHON] (Bottom) Cooperation between Jupyter Notebook and running Excel

What i did

Use the pywin32 module to COM operate Excel and exchange data. Specifically, it looks like the image below. test.gif

code

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".

Impressions

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

(Bottom) Cooperation between Jupyter Notebook and running Excel
Mutual conversion between Qiita articles and Jupyter notebook
Cooperation between py2exe and setuptools
Cooperation between python module and API
Jupyter Notebook: 4 banal tips and tricks
Try running Jupyter Notebook on Mac
Use Jupyter Lab and Jupyter Notebook with EC2
Jupyter Notebook basic operations and shortcut keys
Linking python and JavaScript with jupyter notebook
Install matplotlib and display graph on Jupyter Notebook
Error running Jupyter Notebook in Anaconda virtual environment
Jupyter Notebook memo
Introducing Jupyter Notebook
Powerful Jupyter Notebook
Jupyter notebook password
Easily launch jupyter notebook on AWS and access locally
Automatically save .py and .html files in Jupyter notebook.
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
Next to Excel, for the time being, jupyter notebook
Make Jupyter Notebook your own: Change background and icons