Pigcowpig
Pigcowpig

Reputation: 211

How can I find the DocsList Sheet ID with the sheet URL

I would like to be able to take a spreadsheet URL value from a cell in the active sheet and be able to add that file to a specific folder. The only thing I think that I am missing is a method to add a file to a folder by URL or to extract the DocsList sheet ID using the URL.

Here is a sample of the code I am using:

var rowNum = 1
var colLet = A
var findFolder = DocsList.getFolder(folderName);
var ssURL = SpreadsheetApp.getActiveSheet().getRange(colLet+rowNum).getValue();
var ssFileFindID = ?
ssFileFindID.addToFolder( findFolder );

Upvotes: 0

Views: 625

Answers (1)

Waqar Ahmad
Waqar Ahmad

Reputation: 3732

You will have to use string manipulation functions to get the id of the spreadsheet from the URL e.g Suppose a spreadsheet url is like the example given below

https://docs.google.com/spreadsheet/ccc?key=xxxxxxxxxxxxxxxxxxxxxx&pli=1#gid=1

var ssURL = SpreadsheetApp.getActiveSheet().getRange(colLet+rowNum).getValue();
var ssFileFindID = ssURL.split('key=')[1].split('&')[0]; //this is ID of file

Hope the above hint will help you

Upvotes: 2

Related Questions