如何将这个textFinder转换为仅返回在特定列中找到的电子邮件?

huangapple go评论69阅读模式
英文:

How do I convert this textFinder to only return the email it finds in a specific column?

问题

以下是您要翻译的内容:

"我目前有一个员工详细信息的电子表格表格。只要电子邮件地址是唯一的(在表格的列E中只出现一次),下面的代码就可以正常工作。然而,其他用户的电子邮件地址也可以在主管/经理列的电子邮件中找到,这会导致下面的代码引用第一个电子邮件出现,从而混乱用户的全名输出。我想要做的是只在特定列,即列E中搜索用户的电子邮件。

var userEmail = Session.getActiveUser().getEmail();
var url = '';
var ss = SpreadsheetApp.openByUrl(url);
var thisSheet = ss.getSheetByName("employeeList");
var tf = thisSheet.getRange("A1:Z" + thisSheet.getLastRow()).createTextFinder(userEmail);
var userFullName = tf.findNext().offset(0, -4, 1, thisSheet.getLastColumn()).getValues()[0][1];
console.log(userFullName);

希望这有帮助。

英文:

I currently have a Spreadsheet table of employee details. The code below works fine as long as the email is unique (only one occurrence in the table's column E). However, other user emails are also found in the supervisor/manager columns email, which results into the code below referencing that first email occurrence and thus messing up the userFullName output. What I wanted to do is to search only a specific column, column E, for the userEmail.

   var userEmail = Session.getActiveUser().getEmail();
   var url = '';
   var ss= SpreadsheetApp.openByUrl(url);
   var thisSheet = ss.getSheetByName("employeeList");
   var tf = thisSheet.getRange("A1:Z" + thisSheet.getLastRow()).createTextFinder(userEmail);
   var userFullName = tf.findNext().offset(0, -4, 1, thisSheet.getLastColumn()).getValues()[0][1];
   console.log(userFullName);

答案1

得分: 1

从 "我想要做的是只在特定列,即列E中搜索userEmail。",如果你想要从只有 "E" 列中搜索 "userEmail" 的值,可以如下修改:

从:

var tf = thisSheet.getRange("A1:Z" + thisSheet.getLastRow()).createTextFinder(userEmail);

到:

var tf = thisSheet.getRange("E1:E" + thisSheet.getLastRow()).createTextFinder(userEmail);
  • Range类的createTextFinder方法可以在指定范围内搜索值。

  • 根据你的脚本,假设没有标题行。如果你有标题行,请将 E1:E 修改为 E2:E

英文:

From What I wanted to do is to search only a specific column, column E, for the userEmail., if you want to search a value of userEmail from only column "E", how about the following modification?

From:

var tf = thisSheet.getRange("A1:Z" + thisSheet.getLastRow()).createTextFinder(userEmail);

To:

var tf = thisSheet.getRange("E1:E" + thisSheet.getLastRow()).createTextFinder(userEmail);
  • The method of createTextFinder of Class Range can search the value from the range.

  • From your scriptm, it supposes that there is no header row. If you have a header row, please modify E1:E to E2:E.

huangapple
  • 本文由 发表于 2023年2月27日 16:23:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578178.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定