Python から Excelのデータを操作するために!
Excelファイルを読み書きするためのライブラリは いくつかあるみたいですが 今回は OpenPyXL を インストールしていきます。

VS の 「ソリューションエクスプローラ」→「pythonの環境」を右クリックから 「すべてのpythonの環境の表示」をクリックします。

目的のPython環境を選択後、「概要」をクリックして「パッケージ(PyPl)」を選択します。

「PyPl と インストールされた パッケージの検索」 に 「OpenPyXL」を入力。
表示された「次のコマンドを実行する pip install OpenPyXL」をクリック。

「昇格」を求めるられるので 「今すぐ昇格」してインストールをしていきます。
仮想環境を作成していると、環境に合わせて ライブラリを管理できます。
動作確認
import openpyxl
filename = r"D:\temp\test.xlsx"
wb = openpyxl.load_workbook(filename)
ws = wb["Sheet1"]
c = ws.cell(1, 1).value
print(c) # セルA1の値を表示
外部リンク
OpenPyXL の公式ドキュメント:
https://openpyxl.readthedocs.io/en/stable/index.html
公式の説明 – 手順 5 – Python 環境へのパッケージのインストール:
https://docs.microsoft.com/ja-jp/visualstudio/python/tutorial-working-with-python-in-visual-studio-step-05-installing-packages?view=vs-2019
コメント