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

【GAS】Unexpected error while getting the method or property openById on object SpreadsheetApp.の対処

Last updated at Posted at 2024-02-09

事象

GAS(Google Apps Script)でopenByIdで既存のspreadsheetを開く処理で以下のエラーになる。

Exception: Unexpected error while getting the method or property openById on object SpreadsheetApp.

原因

Google Spreadsheetの「ID」を勘違いしていた。

SpreadsheetのIDは、docs.google.com/spreadsheets/d/
の直後に付いている40文字くらいの長い文字列。

URLの最後についている10桁前後の数字(gid=xxxxxxxxxx)ではない。

解決方法

var ss = SpreadsheetApp.openById(xxxxxxxxxx);

の「xxxxxxxxxx」を
docs.google.com/spreadsheets/d/
の直後に付いている長い文字列に変更する。

もしもIDが長すぎてエラーになる場合には、openByIdの代わりにopenByUrlを使う。

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