问题
I have a function that returns a string that are the cells that I need to scan with the UNIQUE() built-in function, but it does not process the returned value.
Tried putting them in quotes, didn't help.
function GetRange(sheet, ColumnLetter , Offset)
{
var startColumn = letterToColumn(ColumnLetter);
var string = "";
for(var i=startColumn; i <= Offset; i++)
{
string += sheet + "!" + columnToLetter(i) +":"+columnToLetter(i)+";";
}
string = string.substring(0, string.length-1);
return string+"";
}
On the Sheet side I have this in a cell
=UNIQUE({GetRange("Raid","C", 30)})
I expected to get the returned string into the built-in UNIQUE()
function, and execute the code like I would if I would have typed it in manually.
Instead, it just outputs the returned string into the cell like this
Raid!C:C;Raid!D:D;Raid!E:E;Raid!F:F;Raid!G:G;Raid!H:H;Raid!I:I;Raid!J:J;Raid!K:K;Raid!L:L;Raid!M:M;Raid!N:N;Raid!O:O;Raid!P:P;Raid!Q:Q;Raid!R:R;Raid!S:S;Raid!T:T;Raid!U:U;Raid!V:V;Raid!W:W;Raid!X:X;Raid!Y:Y;Raid!Z:Z;Raid!AA:AA;Raid!AB:AB;Raid!AC:AC;Raid!AD:AD
回答1:
try like this instead:
=ARRAYFORMULA(SORT(UNIQUE(TRANSPOSE(SPLIT(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(LEN(Raid!A1:A), IF(Raid!C1:AL<>"", "♦"&Raid!C1:AL, ), )),,999^99)),,999^99)), "♦")))))
回答2:
Issue:
You're returning a string from the function. It can't be evaluated as a spreadsheet array literal by the spreadsheet.
Solution:
Return arrays instead.
Snippet:
/**
* @param {Raid!C:AD} range - Range to stack as a array
* @return The provided 2D array stacked up vertically
* @customfunction
*/
function stackUp(range) {
return Array.prototype.concat.apply(
[],
range[0].map(function(col, i) {
//for each column
return range
.map(function(row) {
return [row[i]];
}) //get each row in this column
.filter(String); //ignore empty rows
})
);
}
来源:https://stackoverflow.com/questions/56562774/how-do-i-return-a-string-that-the-built-in-google-spreadsheet-function-can-us