谷歌电子表格获取单元格指向的地址

发布于 2024-12-15 21:03:28 字数 727 浏览 0 评论 0原文

我有一个如下表所示的电子表格

+---+-----------------+-----+--------------------------------+
|   |        A        |  B  |               C                |
+---+-----------------+-----+--------------------------------+
| 1 | This is my text | =A1 | 'This should be the value "A1" |
+---+-----------------+-----+--------------------------------+

,其中 A1 是文本“这是我的文本”,B1 是函数 =A1。我需要一个 C1 函数来为我提供文本 A1,因为这是 B1 指向的单元格。 INDEX间接 似乎没有给我我想要的东西。

I have an spreadsheet like the table below

+---+-----------------+-----+--------------------------------+
|   |        A        |  B  |               C                |
+---+-----------------+-----+--------------------------------+
| 1 | This is my text | =A1 | 'This should be the value "A1" |
+---+-----------------+-----+--------------------------------+

where A1 is the text "This is my text", and B1 is the function =A1. I need a function for C1 that gives me the text A1, because that's the cell that B1 points to. INDEX and INDIRECT do not seem to give me what I'm after.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

平定天下 2024-12-22 21:03:28

据我所知,没有 Google 电子表格函数可以返回单元格的公式,但您可以使用脚本编辑器定义自定义函数。定义一个自定义函数公式,在给定单元格的行号和列号的情况下,该函数返回单元格的公式。然后在单元格 C1 的公式中使用自定义函数。单元格 C1 的公式将包含:

=formula(1,2)

这将导致单元格 C1 的值成为字符串:

"=A1"

对单元格 C1 中的公式进行一些有用的改进。首先,使用 row()column() 函数根据单元格引用计算行和列:

=formula( row(B1) , column(B1) )

其次,剪掉 = (根据您的问题陈述,您不需要):

=mid( formula(row(B1),column(B1)) , 2 , 9999 )

要定义函数公式,请转到“工具”、“脚本编辑器”,然后输入以下脚本:

function formula(r,c) {
  return SpreadsheetApp . getActiveSheet() . getRange(r,c) . getFormula() ;
}

I know of no Google Spreadsheet function which returns the formula of a cell, but you can define a custom function using the Script Editor. Define a custom function formula which returns the formula of a cell, given the row and column number of the cell. Then use the custom function in the formula of cell C1. The formula of cell C1 would contain:

=formula(1,2)

And this would cause the value of cell C1 to be the string:

"=A1"

A couple of useful refinements to the formula in cell C1. First, calculate the row and column from a cell reference using the row() and column() functions:

=formula( row(B1) , column(B1) )

Second, trim off the = (which, according to your problem statement, you do not want):

=mid( formula(row(B1),column(B1)) , 2 , 9999 )

To define the function formula, go to Tools, Script Editor, and enter the following script:

function formula(r,c) {
  return SpreadsheetApp . getActiveSheet() . getRange(r,c) . getFormula() ;
}
撞了怀 2024-12-22 21:03:28

我知道这个问题被问到已经有九年了,但由于只有一个答复,而且它以“我不知道有任何 Google 电子表格函数可以返回单元格公式”开头,所以我想我应该继续,回答这个问题是因为事实上有一个函数可以返回单元格的公式。

=FORMULATEXT([CELL])

这将完全按照它的说明执行,并返回该单元格内的公式文本。从那里您可以使用标准字符串函数 LEFT、RIGHT、MID 从中提取您想要的内容。

I know it's been like nine years since this question was asked, but since there is only one response and it starts out with "I know of no Google Spreadsheet function which returns the formula of a cell", I figured I'd go ahead and answer this since there is, in fact, a function that returns the formula of a cell.

=FORMULATEXT([CELL])

This will do exactly as it says and return the text of the formula within that cell. From there you can use the standard string functions LEFT, RIGHT, MID to extract what you want out of it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文