如何根据同一工作表中列的特定值在 Google 工作表的另一列中设置值

How to set value in another column of Google Sheets based on certain value of column in the same sheets

我有一张包含电子邮件地址列表的表格。我想根据 B 列中电子邮件的值自动填充 D 列。

我想在 D 列中自动填充的是电子邮件地址的名字。

我想要的是这样的:

假设我知道,或者我可以设置电子邮件列表的名字。

问题是如何根据电子邮件地址的值自动填充列 D 或 (NAME)。

请注意,数据(A 至 C 列)是根据 Google 表格自动填充的。

在单元格 D1:

中试试这个数组公式
=ARRAYFORMULA({"NAME";proper(REGEXEXTRACT(B2:INDEX(B:B,COUNTA(B:B)),"^[a-z]+"))})


作为 Google Apps Script 中的完整解决方案,您可以这样做:

function myFunction() {
  
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Form Responses 1");
  const emails = sh.getRange("B2:B"+sh.getLastRow()).getValues().flat();
  const names = emails.map(str=>str.match('^[a-z]+')[0])
                .map(name=>name.charAt(0).toUpperCase()+name.slice(1));
  sh.getRange("D2:D"+sh.getLastRow()).setValues(names.map(nm=>[nm]));
}

假设 sheet 名称是 Form Responses 1


举例说明:

const emails = ['ken@gmail.com','kobe.brayant@gmail.com',
                  'ben02@hotmail.com','lebronJAMES@gmail.com']; 
const names = emails.map(str=>str.match('^[a-z]+')[0])
                .map(name=>name.charAt(0).toUpperCase()+name.slice(1));
console.log(names);