简体   繁体   中英

Google Spreadsheet setFontColor error - you do not have permission to call setFontColor

I have a Google Spreadsheet , with the following function:

function setcolor(color) 
{
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getActiveSheet();
   var range = ss.getActiveRange();
   range.setFontColor(color);
}

In cell A1 I have the following formula:

=setcolor("red");

Upon evaluating, Google returns an error in the cell:

error: You do not have permission to call setFontColor (line 6, file "Code")

Screen shot: http://snag.gy/nQDpy.jpg

The spreadsheet is open (anyone with link can edit). I read in the help file that the cell that is being evaluated needs to be referenced with getActiveRange - perhaps I am interpreting this wrong?

You are not allowed to modify the spreadsheet from within a custom function. Even if you were allowed it would still not work for many reasons like (1) custom functions must only act on their input and not external things (see this for example for a longer explanation Custom Google Sheets function ) and (2) the cell with the formula is unrelated to the active cell, would only work if you just entered the formula. Tldr thats not how to use custom functions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM