Wednesday, October 10, 2012

Google Spreadsheet Script to get the Parent Folder


I need to write a custom Spreadsheet function (apps script) that shows the name of the folder it is in. 
I tried getParents but that is not available to SpreadsheetApp.getActiveSheet().


Following is the script that give you the name of parent folder of the active spreadsheet:

function getParentFolder() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ssId = ss.getId();
  var file = DocsList.getFileById(ssId);
  var fileId = file.getId();
  var ParentFolders = file.getParents();

Note: To run this code you will have to authorize the script, and after authorization you will be able to use the above function.

And If you are not much familiar with scripts then check out the following link:

I hope the above solution will help you, and if you need more help then please do comment below on this blog itself, I will try to help you out.

I also take up private or confidential projects:

If this blog post was helpful to you, and if you think you want to help me too and make my this blog survive then please donate here: 


No comments:

Post a Comment