3
0

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 1 year has passed since last update.

【Python】gspreadで最終行数を取得する方法

Last updated at Posted at 2023-06-12

前置き

GASであれば、「.getLastRow」とすれば取得できますよね。
ですがPythonのgspreadにはこのようなメソッドがありません。

検索等でヒットするのは「ws.row_count」ですが空白のセルの分まで含まれてしまいます。
空のセルまでfor文をぐるぐる回すのもAPIの制限に引っかかる為、推奨できません。

取得方法

example.py
last_row =len(ws.col_values(1))
print(last_row)

これで取れます。

解説

len(ws.col_values(1))

ここでA列全てをリスト化し、lenで要素数をカウントしています。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?