LoginSignup
2

More than 5 years have passed since last update.

Google Sheets API の "Attempting to write column: 26, beyond the last requested column of: 25" というエラーの意味がわかった

Posted at

問題

Spreadsheet API の create ( https://developers.google.com/sheets/reference/rest/v4/spreadsheets/create ) で、26番目以降の column にどうしてもデータを入力できないというエラーレスポンスでハマりました。英語は読めないし message でググってもわからなくて本当に参った。

{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid sheets[1].data[4]: Attempting to write column: 26, beyond the last requested column of: 25",
    "reason" : "badRequest"
  } ],
  "message" : "Invalid sheets[1].data[4]: Attempting to write column: 26, beyond the last requested column of: 25",
  "status" : "INVALID_ARGUMENT"
}

原因

何かと思ったら Sheet デフォルトの最終列がアルファベット 0 ベースで 25 番目の Z なんですよね。それを超えるような位置に、 API リファレンスでいうところの SheetGridDataRowDataCellData を入力したとしても、自動では拡張してもらえず弾かれるということでした。
image

解決

それ用のオプションがあります。 SheetSheetPropertiesGridProperties ( https://developers.google.com/sheets/reference/rest/v4/spreadsheets#gridproperties ) の columnCount を十分な大きさに設定してやることで解決しました。
image

あとがき

同じく rowCount を設定してやることが必要な場面もあるでしょう。もちろんこのオプションで逆に狭めることもできます。それにしてもスプレッドシートは複雑ですが、この API 群はよく作ってありますね。

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
2