[英]Google Spreadsheets function to get a cell from a range by row and col name
I have a range 我有范围
idz01 idz04 ida02
foo a 1 b
bar c 3 8
baz 8 2 g
And I want to get values from this range, like this: 我想从这个范围获取值,像这样:
SOME_FUNCTION(rangeID, 'foo', 'idz04')
to get 1
, etc. Or ideally, to get the cell: 得到1
,等等。或者理想情况下,得到单元:
INDIRECT(SOME_FUNCTION(rangeID, 'foo', 'idz04'))
or such. 等等。
Is there something such? 有这样的东西吗? Can the GETPIVOTDATA()
be used for that? 可以使用GETPIVOTDATA()
吗?
Edit: I could somehow employ the LOOKUP
if I was able to get the result_range
: 编辑:如果我能够得到result_range
我可以以某种方式雇用LOOKUP
:
LOOKUP("foo", DataRange,
FIRST_COL(
OFFSET(DataRange,
MATCH("idz04", FIRST_ROW(DataRange), 0)
)
)
)
Only, I don't have FIRST_ROW()
and FIRST_COL()
... Maybe FILTER()
could help? 只是,我没有FIRST_ROW()
和FIRST_COL()
...也许FILTER()
可以帮助吗?
Try this, you just need to set ranges: 试试这个,您只需要设置范围:
=INDEX("Talbe",MATCH("foo","First Column",0),MATCH("idz04","First Row",0))
For example if your table is in the range A1:D4, use: 例如,如果您的表在A1:D4范围内,请使用:
=INDEX(A1:D4,MATCH("foo",A:A,0),MATCH("idz04",1:1,0))
You can also use named ranges 您还可以使用命名范围
To get first columns and rows automatically use this formula: 要自动获取第一列和行,请使用以下公式:
=INDEX(data,MATCH("foo",INDIRECT(CHAR(64+COLUMN(data))&":"&CHAR(64+COLUMN(data))),0),MATCH("idz04",INDIRECT(COLUMN(data)&":"&COLUMN(data)),0))
To do this via script, use this code: 要通过脚本执行此操作,请使用以下代码:
function LOOKUPGRID(data, rowHeader, colHeader) {
for (var i = 0; i<data.length;i++) {
if (data[i][0] === rowHeader) {
for (var j = 0; j<data[0].length;j++) {
if (data[0][j] === colHeader) {
return (data[i][j]);
}
}
}
}
return (null)
}
You can then call the formula in your sheet like this: 然后,您可以像这样在工作表中调用公式:
=LOOKUPGRID(A1:D4,"foo","idz04")
For this you could write a custom function using Google Apps Script. 为此,您可以使用Google Apps脚本编写自定义函数。 Check this documentation for more details. 查看此文档以了解更多详细信息。
You could access the spread sheet with name or id and get the range of values(in your case a cell). 您可以使用名称或ID访问电子表格并获取值的范围(在您的情况下为单元格)。
Hope that helps! 希望有帮助!
Here it goes: 它去了:
=INDEX(ObjednavkyData,
// Find the offset of "vesela01" in the 1st column
MATCH("vesela01",
OFFSET((ObjednavkyData),0,0,
MAX(ARRAYFORMULA(ROW(ObjednavkyData))) // Num of rows in the range
, 1)
,0),
// Find the offset of "z03" in the 1st row
MATCH("z03",
OFFSET(ObjednavkyData, 0 , 0, 1) // First row
, 0))
Not really neat :P 不是很整洁:P
Also see Google Spreadsheets: How to get a first (Nth) row/column from a range? 另请参阅Google Spreadsheets:如何从范围中获取第一行(第N行)? (built-in functions) (内置功能)
Tried to write my own function... 试图写我自己的功能...
/**
* Returns [Range] the cell value at coordinates determined by the values first row (colHeader) and first column (rowHeader) in given range.
*/
function LOOKUP_GRID(range, colHeader, rowHeader){
for(var col = range.getWidth()-1; col--; col >= 0 )
if(range.getCell(1, col).getValue() === colHeader)
break;
for(var row = range.getHeight()-1; row--; row >= 0 )
if(range.getCell(row, 1).getValue() === rowHeader)
break;
if(col === -1 || row === -1)
return null;
else
return range.getCell(row, column)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.