Apps Script公式リファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2020年8月16日日曜日

スプレッドシートにsetValue()で配列を入れる時はtoString()してやる

toString()しないと先頭の要素しか入らなかった。



MISSION
スプレッドシートにsetValue()で配列を入れる


BEFORE 
toString()しないと先頭の要素しか入らない。

  const array = ["hello", "hi"];
  sheet.getRange("A1").setValue(array);



AFTER 
toString()すると要素たちが入る。

  const array = ["hello", "hi"].toString();
  sheet.getRange("A1").setValue(array);



KEY
配列をtoString()する。



コード.gs
function dummy() {// これはうまくいかない
  const url = "SPREADSHEET_URL";
  const sheet = SpreadsheetApp.openByUrl(url).getSheets()[0];
  const array = ["hello", "hi"];
  sheet.getRange("A1").setValue(array);
}


function SetValueToString() {// これでうまくいった
  const url = "SPREADSHEET_URL";
const sheet = SpreadsheetApp.openByUrl(url).getSheets()[0]; const array = ["hello", "hi"].toString(); sheet.getRange("A1").setValue(array); }


参考 

setValue(value)

Latest post

Google Apps Scriptの障害時はIssueTrackerを見てみる - Incidents for Apps Script are reported on Issue Tracker

IssueTracker > Apps Script issues https://issuetracker.google.com/savedsearches/566234 Google Apps Scriptの障害時は IssueTracker に課題が上がっていることが...