简体   繁体   English

Google Spreadsheets函数通过行和列名称从范围中获取单元格

[英]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.

相关问题 谷歌表格脚本:从当前单元格获取多列/行命名范围 - Google Sheets Script: Get Multi-Col/Row Named Range from Current Cell 谷歌电子表格 | 如何获取范围内的第一个和最后一个活动单元格,然后返回该单元格的单元格偏移量 - Google Spreadsheets | How to get the first and last active cell in a range, and then return a cell offset from that cell 如何获取传递为Google Spreadsheets中的函数参数的单元格的值? - how to get value of cell passed as function parameter in Google Spreadsheets? 如何将范围传递给 Google 电子表格中的自定义函数? - How to pass a range into a custom function in Google Spreadsheets? Google Spreadsheets获取单元格注释/注释 - Google Spreadsheets Get Cell Comments/Notes 从单元格导入 XML 内容 – Google 电子表格 - Import XML content from a cell – Google spreadsheets 如果行中的单元格值为 0 或空白,则删除 Google 电子表格中的一行 - Delete a row in Google Spreadsheets if value of cell in said row is 0 or blank 从谷歌电子表格中的单元格调用 showSidebar() - Call showSidebar() from a cell in google spreadsheets Google Spreadsheets ArrayFormula:如何拆分和转置单元格范围? - Google Spreadsheets ArrayFormula: How to split and transpose a cell-range? Google Sheet 自定义功能 - 如果单元格不为空,如何从范围中获取单元格位置 - Google Sheet Custom Function - how get cell locations from a range if cell is not blank
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM