是否有使用類似于 VLOOKUP 的 Google App Scripts 的選項?
我希望有一個解決方案可以???使用 GAS 觸發器功能在預定的基礎上用電子表格 1 上的電子郵件替換電子表格 2 上的電子郵件。
目前我正在使用公式,但它們會降低我的作業表的性能。我不需要他們每 24 小時獲取一次以上的資料,因此我想使用 GAS 代替觸發器。
- IMPORTRANGE & QUERY 將電子表格 #1(ID、電子郵件 1、電子郵件 2)匯入電子表格 #2
=QUERY(IMPORTRANGE(spreadsheet_url, A1:E), "SELECT Col1,Col4,Col5 WHERE A Col1 is not null", 1) - 然后在電子表格 #2 上使用 ARRAYFORMULA 和 VLOOKUP 填充所有電子郵件。
=ARRAYFORMULA(VLOOKUP(Sheet1!A2:A,ImportedData!A2:C},{2,3},0)
這是我的 2 個電子表格的樣子...
電子表格 #1(包含約 200 萬個單元格)
| ID | 某物 | 某物 | 郵箱1 | 電子郵件2 |
|---|---|---|---|---|
| 111111 | * | * | [email protected] | 鮑勃@gmail.com |
| 222222 | * | * | [email protected] | [email protected] |
電子表格 #2(包含約 20 萬個單元格)
| ID | 電子郵件 1 | 電子郵件 2 |
|---|---|---|
| 111111 | ??? | ??? |
| 222222 | ??? | ??? |
更新
我在這里問了一個類似的問題并得到了答案。
答案是:
function myFunction() {
const sss = SpreadsheetApp.openById('ABC');
const ssh = sss.getSheetByName("MasterDB");
const mDB = ssh.getRange("A2:C" ssh.getLastRow()).getValues(); //Get's ID's from Master Spreadsheet
const dss = SpreadsheetApp.openById('XYZ');
const dsh = dss.getSheetByName("ChildDB");
const cDB = dsh.getRange("A2:A" dsh.getLastRow()).getValues(); //Get's ID's from Child Spreadsheet
// Create an object for searching the values of column "A".
const obj = mDB.reduce((o, [a, ...bc]) => ((o[a] = bc), o), {});
// Create an array for putting to the Spreadsheet.
const values = cDB.map(([b]) => obj[b] || ["", ""]);
// Put the array to the Spreadsheet.
dsh.getRange(2, 2, values.length, 2).setValues(values);
}
我的新問題(對于這個執行緒)
如何修改腳本以排除 B 列和 C 列?
uj5u.com熱心網友回復:
在您的情況下,我認為您的目標可能可以通過腳本中的以下 2 個修改點來實作。
從:
const mDB = ssh.getRange("A2:C" ssh.getLastRow()).getValues();
到:
const mDB = ssh.getRange("A2:E" ssh.getLastRow()).getValues();
另外,請修改如下。
從:
const obj = mDB.reduce((o, [a, ...bc]) => ((o[a] = bc), o), {});
到:
const obj = mDB.reduce((o, [a,,,...de]) => ((o[a] = de), o), {});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/384479.html
