LoginSignup
0
1

More than 3 years have passed since last update.

【Python】読込むブック名とセルの値をパラメーターにする。②

Last updated at Posted at 2021-02-21

pythonを使用してExcelファイルの操作を勉強しています。
本日の気づき(復習)は、パラメーターに関してです。
pythonでExcelを操作するため、openpyxlというパッケージを使用しています。

後々レイアウトを変更したり、プログラムで読み込むブック名やセルの値を変えてしまうかもしれない時の対処法です。
なんだかちょっと実戦形式っぽくてワクワクしてます。

今回はこちらのブック「日報.xlsx」を、使用します。
image.png

input関数

input関数を使うとプログラム実行時に対話形式でパラメーターを入力できることが強みですね。

input(コマンドラインに表示する文言)
input_arguments.py
from openpyxl import load_workbook

filename = input('読込むブック名: ')
cellno = input('読込むセル名(例 A1): ')

wb = load_workbook(filename, read_only=True)
ws = wb.active

print(ws[cellno].value)
読込むブック名: 日報.xlsx
読込むセル名(例 A1): I1
-->hogehoge

以前勉強したところでもあり、こちらはすんなり腹に降りてきてくれました。

0
1
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
0
1