简体   繁体   English

如何使用单元格值搜索行索引

[英]How to search row index using cell value

I am using google spreadsheet API v4 for java. 我正在使用Java的Google电子表格API v4。

My Spreadsheet looks something like this - 我的电子表格看起来像这样-

    User    Message       Time
--------------------------------

    User1    My Message    10:30
    User2    User2 msg     3:40
    User3    User3 msg     1:30
    User2    User2 msg       
    User4    User4 msg     4:00 

I want to find row index with User 'User2' and Time bank (empty value). 我想用用户'User2'和Time bank(空值)查找行索引。 After that, I would like to use this row index to add time value in that row. 之后,我想使用此行索引在该行中添加时间值。 Is it possible to search row by cell values without knowing range or index? 是否可以在不知道范围或索引的情况下按单元格值搜索?

In above example, it should return me only second last row index as it matches to the criteria (User='User2' and Time=''). 在上面的示例中,它应仅返回第二行索引,因为它与条件(User ='User2'和Time ='')匹配。 or even better, is there any find and replace API, which will find row criteria (User='User2' and Time='') and replace Time value from '' to '3:30'? 甚至更好的是,是否有任何查找和替换API,它将查找行条件(User ='User2'和Time ='')并将Time值从''替换为'3:30'?

I went through google docs, but could not find one according to my need. 我浏览了google文档,但找不到符合我需要的文档。 Thanks. 谢谢。

Edit: 编辑:

I found a formula to find cell address which needs to be updated. 我找到了一个公式来查找需要更新的单元格地址。

=ADDRESS(MATCH("User2",A1:A4000),3)

For example used in this question, this formula will return '$C$4' address, which is expected. 例如,在此问题中使用的此公式将返回“ $ C $ 4”地址,这是预期的。 I tested this by evaluating this formula in spreadsheet manually. 我通过在电子表格中手动评估此公式对此进行了测试。 Is there any way using Google spreadsheet API V4 to evaluate this formula using Java code? 是否可以使用Google电子表格API V4使用Java代码评估此公式?

I think you'd want to use a combination of lookup functions: https://support.google.com/docs/topic/3105472?hl=en&ref_topic=3046366 我认为您想结合使用查找功能: https : //support.google.com/docs/topic/3105472?hl=zh_CN&ref_topic=3046366

In particular, MATCH lets you get a position offset of the value you want in a range, so you could get the offset of the cells in column1 containing values 'User2', and OFFSET could let you check the value in the cell 2 columns to the right of the found cell, which would give you the value in the Time column to compare with. 特别是,MATCH可以让您获得所需值在某个范围内的位置偏移,因此您可以获取column1中包含值'User2'的单元格的偏移量,而OFFSET可以让您检查单元格2列中的值以在找到的单元格的右边,这将为您提供“时间”列中的值以进行比较。 Since then you'd also have the cell coordiates of the thing checked, you could then assign a new value. 从那时起,您还需要检查事物的单元格坐标,然后可以分配一个新值。 These lookup functions allow you to find the range or index that you need for the rest. 这些查找功能使您可以查找其余所需的范围或索引。

This just gives you a handy way to have certain values precomputed for your other functions so that your script can get direct access to values output by the sheets builtin functions. 这只是给您一种方便的方法,可以为其他函数预先计算某些值,以便您的脚本可以直接访问内置表功能的输出值。 It saves having to have your sheets script sort through a range for a value, but the logic is the same. 不必让工作表脚本对值的范围进行排序,但是逻辑是相同的。 1) Get range for Column1 2) Search range of Column1 for value 'User2' 3) If matched, check offset(0,2) to get the cell reference 2 spaces to the right and ask for its cell reference. 1)获取Column1的范围2)在Column1中搜索值'User2'的范围3)如果匹配,请检查offset(0,2)以将单元格引用2移到右边,并要求其单元格引用。 4) If that reference is empty, assign it a timestamp. 4)如果该引用为空,请为其分配一个时间戳。

If you want the code for this, it'll take me a bit longer to put together. 如果您要使用此代码,则需要花费更长的时间才能完成。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在表中搜索值,然后在同一行上获取其他单元格值? - How can I search a value in a table and then get the other cell value on the same row? APACHE POI,如何找到一个单元格的行索引? - APACHE POI, how to find the row index of a cell? 如何使用硒(JAVA)按列名和行索引自动点击表格单元格中的链接 - How to automate click link in table cell by column name and row index using selenium (JAVA) 使用行和列在特定索引处获取值 - Get Value at Specific Index using Row and Column 如何使用Java POI从Excel获取有关行和列值的特定单元格值 - How to get Specific Cell Value from Excel With Respect To Row And Column Value using Java POI 如何更改给定行和索引处单元格的背景颜色? - how can I change the background color of a cell at a given row and index? 如何使用合并的单元格值大于单元格宽度的Apache-POI增加excel行的高度? - How to increase the height of the excel row using Apache-POI having merged cell value greater than the cell width? 如何使用Java从Excel工作表中获取特定列名(作为参数传递)的最后一个非空单元格的行索引? - How to get the row index of last non-empty cell for a specific column name(passed as an argument) from an excel sheet using java? 如何在数据集中搜索值<row>在 java 火花?</row> - How to search value in Dataset<Row> in java spark? 如何使用apache lucene索引优化搜索 - how to refine the search using apache lucene index
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM