![](/img/trans.png)
[英]Find the value of html table cell by passing column name for a particular row
[英]Search a cell value within a column of values to find row number
我有一個庫存清單表,我有一個購物清單表。 我正在編寫onEdit()函數的腳本,該函數在購物清單工作表的某個單元格中獲取名稱(代碼),並在庫存清單工作表的名稱列中進行搜索。 找到精確匹配后,它將返回行號,我將進行下一步。
問題:
//sheetss name
var inventory = "inventory"
var shopping = "shopping"
// sheets
var ss = SpreadsheetApp.getActiveSpreadsheet()
var activeSheet = ss.getActiveSheet()
var inventorySheet = ss.getSheetByName(inventory)
var lr = anbardariSheet.getLastRow()
//var sh = getSheet(); //custom function that returns target Sheet;
var rng = activeSheet.getRange(3,3, lr, 1); //change to desired Range boundaries;
//create TextFinder and configure;
var tf = rng.createTextFinder('14'); //
tf.matchCase(false); //{Boolean} -> match target text's case or not;
tf.matchEntireCell(false); //{Boolean} -> check the whole Range or within;
tf.ignoreDiacritics(true); //{Boolean} -> ignore diacretic signs during match;
tf.matchFormulaText(false); //{Boolean} -> search in formulas (if any) or values;
//invoke search;
var res = tf.findNext();
//do something with result;
if(res!==null) {
var vals = res.getvalues();
Logger.log(vals);
}
我認為您的代碼中可能有一些問題可以實現您想要的:
1)您正在activeSheet中進行搜索,確定這是庫存表嗎?
2)您正在使用具有錯誤參數的matchEntireCell [1],如果要完全匹配,則必須使用真實參數,否則將像現在一樣具有部分匹配項(即14可以與2214匹配)。
我解決了之前的問題,這是我在onEdit函數中測試的代碼。 我從購物清單的最后一行得到了要比較的值。
//sheetss name
var inventory = "inventory"
var shopping = "shopping"
// sheets
var ss = SpreadsheetApp.getActiveSpreadsheet()
var shoppingSheet = ss.getSheetByName(shopping)
var inventorySheet = ss.getSheetByName(inventory)
var lr = inventorySheet.getLastRow();
//Get value to find
var lrValue = shoppingSheet.getLastRow();
var value = shoppingSheet.getRange(lrValue, 3).getValue();
Logger.log(value)
//var sh = getSheet(); //custom function that returns target Sheet;
var rng = inventorySheet.getRange(3,3, lr, 1); //change to desired Range boundaries;
//create TextFinder and configure;
var tf = rng.createTextFinder(value); //
tf.matchCase(false); //{Boolean} -> match target text's case or not;
tf.matchEntireCell(true); //{Boolean} -> check the whole Range or within;
tf.ignoreDiacritics(true); //{Boolean} -> ignore diacretic signs during match;
tf.matchFormulaText(false); //{Boolean} -> search in formulas (if any) or values;
//invoke search;
var res = tf.findNext();
//do something with result;
if(res!==null) {
var vals = res.getValues();
Logger.log(vals);
Logger.log(res.getA1Notation());
}
[1] https://developers.google.com/apps-script/reference/spreadsheet/text-finder#matchEntireCell(布爾值)
謝謝你們在這么短的時間內回答@Cooper @Andres Duarte
它解決了我的問題,再次感謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.