LoginSignup
4
4

More than 5 years have passed since last update.

DataNitro、シートからデータを読み込む関数の実装

Last updated at Posted at 2014-06-22

privateで少し勉強した位でしばらく放置していたけど、DataNitroをインストールしたので、久しぶりにpythonをいじってみている。
DataNitroなので、(excel)シートからデータを読み込む関数を実装。

def get_sheet_data(shtnam, toprow, keyclm, lftclm, rgtclm):
    row = toprow
    while Cell(shtnam, row, keyclm).value != None:
        row += 1
    if row > toprow:
        return CellRange(shtnam, (toprow, lftclm), (row - 1, rgtclm))
    else:
        return []

キー項目になるカラムのセルが空になるまでチェックするところは、vbaだと、

    Range(sheets(shtnam).Cells(toprow, keyclm), _
            sheets(shtnam).Cells(toprow, keyclm)).Select
    Selection.End(xlDown).Select

として、Selection.rowを参照する実装で調べることができるけど、DataNitroだと
セルを1つ1つ見ていくやり方しかなさそう。
あと、シート上のボタンとかのコントールにアクセスする方法もなさそう。

pythonはあまり使ったことがないけど、クラスとか調べてややこしいなーと、感じてしまった。
この辺は別の記事で書こうかと。

4
4
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
4
4