Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How can I edit a cell in Google Sheets which is linked to a file name in Google Drive?

$
0
0

I currently have a Google Spreadsheet with two columns - the file ID of a set of files, the file name. I want to write a Google Apps Script where when I change the file name within the spreadsheet, it renames the file associated with it (fileID) to the new name and vice versa.

With changing it on the spreadsheet, should I use simple/installable onEdit or onChange, and how might I implement this in code. I don't know how to do this vice versa as well.

Here's what I have so far, but the trigger has failed quite a few times. It's throwing the exception:

Exception: The parameters () don't match the method signature for SpreadsheetApp.Spreadsheet.getRange.at onEdit(edit:3:24)

and

Exception: You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets

  var sheet = SpreadsheetApp.openById("xxx").getSheetByName("New");  var range = e.source.getRange();  range.setComment("Last modified: " + (new Date())+' by '+Session.getActiveUser());  Logger.log(range.getRow() +" " + range.getColumn());  var newName = range.getValue();  var fileID = sheet.getRange(range.getRow(), 1).getValue();  if (range.getColumn == 3) { // just some data validation to make sure the edited cell is in column 3     Logger.log(range.getValue());    var file = DriveApp.getFileById(fileID);    file.setName(newName);  }

Viewing all articles
Browse latest Browse all 9782

Trending Articles