LoginSignup
1
1

More than 5 years have passed since last update.

スプレッドシートのセル取得方法

Last updated at Posted at 2013-08-02

公式ページ

セルを取得する方法自体は下記サンプルに載っています。
https://developers.google.com/google-apps/spreadsheets/?hl=ja#retrieving_a_cell-based_feed

特定のセルのみを取得

上記のやり方に追加して、特定のセルのみを抽出する場合はどうするのかをメモしておきます。
セルを取得するやり方はservice.Queryの部分なので、引数で渡すqueryにどの位置のセルかを書いておきます。

// Fetch the cell feed of the worksheet.
CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);

//2行目の4列目のセルを取得する
cellQuery.Range = "R2C4"; 

CellFeed cellFeed = service.Query(cellQuery);

これで特定のセルのみを取得できるようです。

特定範囲のセルを取得

Rangeというからには特定範囲を取得することもできます。
この場合は

// Fetch the cell feed of the worksheet.
CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink);

//A2:C3の範囲を取得
cellQuery.Range = "A2:C3"; 

CellFeed cellFeed = service.Query(cellQuery);

と書くことでA2:C3の範囲のセルを取得出来ます。

この他にもqueryの各種パラメータを設定することで取得するセルを絞ることができます。

注意

取得しようとしているセルの値が空だと取得できないようです。。。(未検証)

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