Home > database >  Google Apps Script. How do i specify my spreadsheet ID to "Sheet 3"?
Google Apps Script. How do i specify my spreadsheet ID to "Sheet 3"?

Time:01-21

My function should only get information from one sheet within the spreadsheet document. I tried putting the default Spreadsheet ID gid but it is not working. What do i need to do?

var pVorname = Sheets.Spreadsheets.Values.get('1MzLZ.....#gid=594...', 'B2:B100');

CodePudding user response:

In your situation, how about the following modification?

Modified script:

var pVorname = Sheets.Spreadsheets.Values.get('###spreadsheetId###', "'Sheet 3'!B2:B100");
  • By this modification, the values are retrieved from the range of "B2:B100" in "Sheet 3". In this case, please use the sheet name and range as the A1Notation.

  • ###spreadsheetId### is the Spreadsheet ID. For example, when you had used 1MzLZ.....#gid=594..., please modify to 1MzLZ..... by removing #gid=594... as the Spreadsheet ID.

  • From your title of Google Apps Script. How do i specify my spreadsheet ID to "Sheet 3"?, I used Sheet 3 as the sheet name.

Note:

  • If you are required to use the sheet ID, you can also use the following modified script.

      var sheetId = "0";
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getSheets().find(e => e.getSheetId() == sheetId);
      if (sheet) {
        var pVorname = Sheets.Spreadsheets.Values.get(ss.getId(), `'${sheet.getSheetName()}'!B2:B100`);
      }
    

Reference:

  •  Tags:  
  • Related