1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

(ボツ)Jupyter Notebookと起動中のExcelの連携

Posted at

やったこと

pywin32モジュールを使ってExcelをCOM操作してデータをやり取りする。
具体的には下の画像のようになります。
test.gif

コード

単にデータの受け渡しだけなら下記のようにあっさり出来ます。

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()

済んだら「my_app=None」。

所感

普通に使いにくい。Jupyterの拡張書いたりしたらもうちょっと便利になるかもと思っていたが……。特にExcelのundoが効かなくなるのはやはり辛い。これならもう普通にxlsx書き出したほうが便利。しかも、COMが苦行。引数付きプロパティの挙動についていけなくて投げ出した。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?