2
1

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 3 years have passed since last update.

GAS TypeError: output.append is not a function が出る場合の対応方法について

Posted at

はじめに

こんにちは。システムエンジニアのDiavoloです。

GASでWEBアプリを作成する場合、地味に嵌りがちなエラーの回避方法を記事にします。GASのWEBアプリの作成コードを参考にして、GASを作成し実行したときに、「TypeError: output.append is not a function」というエラーが出てしまうことがあります。
昔に書かれた記事のソースコードはChrome V8 ランタイム以前のものがあったりします。output.appendはChrome V8 ランタイムを有効にするとエラーになりますので、GASの設定をoutput.appendはChrome V8 ランタイムを無効にするとエラーが出なくなります。

ソースコード

Chrome V8 ランタイム無効の場合には、このソースコードで問題ありません

index.html
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
  <!-- 先程作成したコード.gsのfunction getData()をコールする -->
  <? var data = getData()?>

  <!-- getData()で取得してきたデータがdataに格納されていますので、これを出力する -->
  <table border=1>
    <?
      for(var i=0; i < data.length; i++){
        output.append('<tr>');
        output.append('<th>' + data[i][0] + '</th>');
        output.append('<th>' + data[i][1] + '</th>');
        output.append('<th>' + data[i][2] + '</th>');
        output.append('</tr>');
      }
    ?>
  </table>
  </body>
</html>

Chrome V8 ランタイムを有効にする場合には、こちらのソースコードになります

index.html
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
  <!-- 先程作成したコード.gsのfunction getData()をコールする -->
  <? var data = getData()?>

  <!-- getData()で取得してきたデータがdataに格納されていますので、これを出力する -->
  <table border=1>
    <?
      for(var i=0; i < data.length; i++){
        output._=('<tr>');
        output._=('<th>' + data[i][0] + '</th>');
        output._=('<th>' + data[i][1] + '</th>');
        output._=('<th>' + data[i][2] + '</th>');
        output._=('</tr>');
      }
    ?>
  </table>
  </body>
</html>

まとめ

TypeError: output.append is not a function が出る場合以下のいずれかの方法を試してください

①GASのChrome V8ランタイムを無効にする

②output.appendをoutput._=に変更する

この記事に掲載したソースコードについては、私の記事から抜粋しています。良かったら覗いてみてくださいませ!!
GoogleAppsScriptとGoogleスプレッドシートを連携したWEBアプリケーションを作成してみた【第二回】

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?