Home > Blockchain >  Get sheet name with url by getting range from a cell
Get sheet name with url by getting range from a cell

Time:01-20

How can I get the sheet name with formula/custom function by getting the cell range which will contain the URL in a spreadsheet?

I'm using the following code, but I get the following error

TypeError: Cannot read property 'length' of undefined
  function getFileNames() {
        var sheet = SpreadsheetApp.getActive().getSheetByName("Links");
        var links = sheet.getRange("B3:B").getValues();
        var filenames = []; 
  for (var i = 0; i < links.length; i  ) {
        var url = links[i][0];
    if (url != "") {
        var filename = SpreadsheetApp.openByUrl(links[i][0]).getName();
       filenames.push([filename]);
   }
 }
  var startRow = 3; // print in row 2 since row 1 is the header row
  var fileNameColumn = 3; // Column B = column 2
  var destination = sheet.getRange(startRow, fileNameColumn, filenames.length, filenames[0].length);
  destination.setValues(filenames);
}

CodePudding user response:

There was already a similar question in this sample

  •  Tags:  
  • Related