RedFalcoN
RedFalcoN

Reputation: 1

Printing the result in Google Sheet Console to the page

I found this function at How to get all tab names/gid:

function GetTabs() {
  var app = SpreadsheetApp;
  var ss = app.openById('1e4zL13L2b8Hs8sJcBw-3_pGjQBecZv_QO_LuSLUrieA');
  var name = ss.getName();
  Logger.log(name);
  var tabs = new Array()
  var sheets = ss.getSheets();
  for (var i = 0; i < sheets.length; i++) tabs.push([sheets[i].getSheetId()])
  //return tabs  
  Logger.log(tabs)
}

It lets me print the GID number of tabs in a spreadsheet to the console. How do I put these GIDs on Sheet2 of the active spreadsheet instead?

Upvotes: 0

Views: 44

Answers (1)

doubleunary
doubleunary

Reputation: 18733

Use Sheet.appendRow(), like this:

function appendSheetIdsToSheet2() {
  const sheetToPrintTo = SpreadsheetApp.getActive().getSheetByName('Sheet 2');
  const ss = SpreadsheetApp.openById('1e4zL13L2b8Hs8sJcBw-3_pGjQBecZv_QO_LuSLUrieA');
  sheetToPrintTo.appendRow([ss.getName()]);
  ss.getSheets().forEach(sheet => sheetToPrintTo.appendRow([sheet.getSheetId()]));
}

Upvotes: 1

Related Questions