custom-function

Passing cell references to spreadsheet functions

僤鯓⒐⒋嵵緔 提交于 2019-11-27 08:57:11
When I call a spreadsheet function, say int(f2) , the function operates on the value in the cell. If cell("F2") contains 3.14159, the result would be 3. But when I call a different type of function — for example: row(f8) — the function takes the cell reference, and not the value, in this case, returning 8. How do I get my custom function to work with the reference, rather than the value? I can pass a string, and use getRange() , but, if I move or update the cells on the sheet, the strings won't change. Really simple example: function GetFormula(cellname) { return SpreadsheetApp.getActiveSheet(

Debugging a custom function in Google Apps Script

假装没事ソ 提交于 2019-11-27 05:28:02
问题 I am trying to create my first custom function for a Google Spreadsheet in Apps Script and I am having a hard time using the debugger. I am working on the custom function demo code from the Google documentation and I have set a breakpoint in the custom function drivingDistance(origin, destination) that is used in a cell of my spreadsheet. The problem I have is, that that the debugger shows the parameters that are passed into the function as being undefined . The content of any other variables

Google Script setValue permission

柔情痞子 提交于 2019-11-27 05:02:59
I'm trying to set some value to a cell in a google docs spreadsheet. function exampleFunction() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var range1 = sheet.getRange("A1"); var value1 = range1.getValue(); value1+=1; range1.setValue(2); return value1; } If I'm trying to affect a cell with this function this error appears: You do not have the permission required to setValue. (line 10, file "ddd") Do you know how I could make that possible? I actually want that the affected cell takes the value of the cell A1 and increase the value of A1 +1. Thank you from

Selecting the last value of a column

牧云@^-^@ 提交于 2019-11-27 03:59:34
问题 I have a spreadsheet with some values in column G. Some cells are empty in between, and I need to get the last value from that column into another cell. Something like: =LAST(G2:G9999) except that LAST isn't a function. 回答1: So this solution takes a string as its parameter. It finds how many rows are in the sheet. It gets all the values in the column specified. It loops through the values from the end to the beginning until it finds a value that is not an empty string. Finally it retunrs the

Supply API key to avoid Hit Limit error from Maps Service in Apps Script

我只是一个虾纸丫 提交于 2019-11-26 17:20:13
问题 I have a Google Sheet where we are fetching the driving distance between two Lat/Lng via the Maps Service. The function below works, but the matrix is 4,500 cells, so I'm getting the "Hit Limit" error. How can I supply my paid account's API key here? Custom Function function drivingMeters(origin, destination) { if (origin=='' || destination==''){return ''} var directions = Maps.newDirectionFinder() .setOrigin(origin) .setDestination(destination) .getDirections(); return directions.routes[0]

How to evaluate a spreadsheet formula within a custom function?

Deadly 提交于 2019-11-26 17:02:25
问题 In a spreadsheet I can enter =SIN(45)+123 in a cell, and it will be evaluated. How can I evaluate spreadsheet functions within a custom function, something like an "eval" function that would work like this : function myFunc() { return Sheet.eval("=SIN(45)+123") } is it possible ? Note that I don't care about the SIN function in particular, what I want is to have access to the complete arsenal of spreadsheet functions ( PMT , QUERY , NPER , etc..) 回答1: Spreadsheet functions from Apps-Script

Google apps script error: “You do not have permission to call protect”

旧城冷巷雨未停 提交于 2019-11-26 14:49:27
问题 I'm trying out my first Google Sheets Apps Script. I'm trying to make a custom function (via a bound script) that will check if the cell it's in is protected. If it is protected, it should change the cell's value to (for now at least) the protection type. I can successfully run the simple demo script in the docs: function DOUBLE(input) { return input * 2; } But when calling Range::protect, I can an error "You do not have permission to call protect" Here's the function function isProtected() {

Refresh data retrieved by a custom function in Google Sheet

不羁岁月 提交于 2019-11-26 10:22:54
I've written a custom Google Apps Script that will receive an id and fetch information from a web service (a price). I use this script in a spreadsheet, and it works just fine. My problem is that these prices change, and my spreadsheet doesn't get updated. How can I force it to re-run the script and update the cells (without manually going over each cell)? tbkn23 Ok, it seems like my problem was that google behaves in a weird way - it doesn't re-run the script as long as the script parameters are similar, it uses cached results from the previous runs. Hence it doesn't re-connect to the API and

Google Script setValue permission

自闭症网瘾萝莉.ら 提交于 2019-11-26 09:53:43
问题 I\'m trying to set some value to a cell in a google docs spreadsheet. function exampleFunction() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var range1 = sheet.getRange(\"A1\"); var value1 = range1.getValue(); value1+=1; range1.setValue(2); return value1; } If I\'m trying to affect a cell with this function this error appears: You do not have the permission required to setValue. (line 10, file \"ddd\") Do you know how I could make that possible? I actually

Syntax behind sorted(key=lambda: …)

无人久伴 提交于 2019-11-26 01:44:23
问题 I don\'t quite understand the syntax behind the sorted() argument: key=lambda variable: variable[0] Isn\'t lambda arbitrary? Why is variable stated twice in what looks like a dict ? 回答1: key is a function that will be called to transform the collection's items before they are compared. The parameter passed to key must be something that is callable. The use of lambda creates an anonymous function (which is callable). In the case of sorted the callable only takes one parameters. Python's lambda