Office-Scripts:将在一个列中作为例外输入的客户-分析师组合添加到另一个 Table
Office-Scripts: Add Client-Analysts combinations entered as exceptions in a column into another Table
在映射 table 中,我有一个 Exceptions
列,其中一些单元格包含具有多个自定义分隔符的字符串,即
Client1~Analyst1*Client2~Analyst2 etc
映射 Table:
+---------------+------------------+----------------------------------------------------+
| Project Owner | Assigned Analyst | Exceptions |
+---------------+------------------+----------------------------------------------------+
| Nico Vera | Maple | Globus Ltd~Walter Lobo*Kevin Kline~Sarah Wick*Monsanto Ltd~Ana Wier |
+---------------+------------------+----------------------------------------------------+
| Vijay Malya | Sonny | |
+---------------+------------------+----------------------------------------------------+
| Sam Tucker | Parvati | Mars~Sonapuri*China Blue~Mona Dsa |
+---------------+------------------+----------------------------------------------------+
| Pessy Shroff | Roy | Harbinger Ltd~Jose Silva*Theos Ltd~Jay Mills |
+---------------+------------------+----------------------------------------------------+
来自另一个FC Table
如下图:
FC Table:
+------+---------------+---------------+
| ID | Project Owner | Client |
+------+---------------+---------------+
| 1001 | Nico Vera | Globus Ltd |
+------+---------------+---------------+
| 1002 | Vijay Malya | Ventura |
+------+---------------+---------------+
| 1003 | Vijay Malya | Ventura |
+------+---------------+---------------+
| 1004 | Sam Tucker | Mocha Coffee |
+------+---------------+---------------+
| 1005 | Nico Vera | Roma Fashions |
+------+---------------+---------------+
| 1012 | Nico Vera | Monsanto Ltd |
+------+---------------+---------------+
| 1006 | Pessy Shroff | Murdoch Ltd |
+------+---------------+---------------+
| 1007 | Pessy Shroff | Harbinger Ltd |
+------+---------------+---------------+
| 1008 | Pessy Shroff | Theos Ltd |
+------+---------------+---------------+
| 1009 | Sam Tucker | Mars |
+------+---------------+---------------+
| 1013 | Sam Tucker | China Blue |
+------+---------------+---------------+
| 1010 | Nico Vera | Kevin Kline |
+------+---------------+---------------+
| 1014 | Nico Vera | Galettos |
+------+---------------+---------------+
每次,我都想将这些独特的项目行拉入另一个名为 Study Report
table 的历史记录 table 并且对于这些行中的每个 Project Owner
,检查任何异常在 Mappings
table 的 Exceptions
列中。
如果给出任何异常,那么对于任何 Client-Analyst
组合,我想添加客户的相应分析师,否则添加映射 table.
的 Assigned Analysts
中给出的默认分析师
学习报告Table:
+------+---------------+---------------+------------------+
| ID | Project Owner | Client | Assigned Analyst |
+------+---------------+---------------+------------------+
| 1001 | Nico Vera | Globus Ltd | Walter Lobo |
+------+---------------+---------------+------------------+
| 1002 | Vijay Malya | Ventura | Sonny |
+------+---------------+---------------+------------------+
| 1003 | Vijay Malya | Fountain Pens | Sonny |
+------+---------------+---------------+------------------+
| 1004 | Sam Tucker | Mocha Coffee | Parvati |
+------+---------------+---------------+------------------+
| 1005 | Nico Vera | Roma Fashions | Maple |
+------+---------------+---------------+------------------+
| 1012 | Nico Vera | Monsanto Ltd | Ana Wier |
+------+---------------+---------------+------------------+
| 1006 | Pessy Shroff | Murdoch Ltd | Roy |
+------+---------------+---------------+------------------+
| 1007 | Pessy Shroff | Harbinger Ltd | Jose Silva |
+------+---------------+---------------+------------------+
| 1008 | Pessy Shroff | Theos Ltd | Jay Mills |
+------+---------------+---------------+------------------+
| 1009 | Sam Tucker | Mars | Sonapuri |
+------+---------------+---------------+------------------+
| 1013 | Sam Tucker | China Blue | Mona Dsa |
+------+---------------+---------------+------------------+
| 1010 | Nico Vera | Kevin Kline | Sarah Wick |
+------+---------------+---------------+------------------+
| 1014 | Nico Vera | Galettos | Maple |
+------+---------------+---------------+------------------+
有谁知道如何拆分 Exceptions 列并使用 Typescript for Excel 执行此操作?任何帮助将不胜感激。
编辑:
....
// pick Opportunity Owner, FC Name, CD Team & Exceptions from Mapping sheet
let mapObj = MapTable.getRangeBetweenHeaderAndTotal().getValues()
.reduce((o, [a, b, c, d]) => Object.assign(o, { [a as string]: [b, c, d] }), {});
let existingIdsObj = StudyTable.getColumnByName("Study Number").getRangeBetweenHeaderAndTotal().getValues().reduce((o, [a]) => Object.assign(o, { [a as string]: true }), {});
let putValues:string[][] = FCTable.getRangeBetweenHeaderAndTotal().getValues().reduce((ar:string[][], [a, b, c, d, e, f, g, h, i, j, k, l,m]) => {
if (!existingIdsObj.hasOwnProperty(a as string)) {
// this is where i need help to define a loop for x
let x: string = (mapObj[d as string][2].trim().toString() !== '' && e.toString().toLowerCase().indexOf(mapObj[d as string][2].toString().toLowerCase().trim().split("~")[0]) !== -1) ? mapObj[d as string][2].trim().split("~")[1].toString() : mapObj[d as string][0].toString();
let y = h.toString();
switch (y) {
case "Active": y = "Open"; break;
case "Cancelled": y = "Cancelled"; break;
case "Completed": y = "Complete"; break;
default: y = "Check"; break;
}
ar.push([b, a, d, e, f, g, , , , , , y, , x, , , , c, k, m]);
}
return ar;
}, []);
// if new studies found, append them to Study Report sheet
if (putValues.length !== 0) {
StudyTable.addRows(-1, putValues);
}
}
...
我玩了一个 office 脚本,试图隔离拆分异常的任务,然后测试您在创建最终 table 时可能 运行 的过滤方法。我不是开发人员,但也许能让你更接近。也许这有帮助...
function main(workbook: ExcelScript.Workbook) {
// simple array of the mapping table used for testing purposes
let exceptionsValues = [
["Nico Vera", "Maple", "Globus Ltd~Walter Lobo * Kevin Kline~Sarah Wick * Monsanto Ltd~Ana Wier"],
["Vijay Malya", "Sonny", ""],
["Sam Tucker", "Parvati", "Mars~Sonapuri * China Blue~Mona Dsa"],
["Pessy Shroff", "Roy", "Harbinger Ltd~Jose Silva * Theos Ltd~Jay Mills"]
];
// augment the original mappings array by creating a new row for each exception (split on the "*") and deleting the row with the concatenated exceptions
exceptionsValues.map((curRow, index) => {
if (curRow[2].indexOf("*") > 0) {
let tempRows = curRow[2].split(" * ");
for (let row of tempRows) {
exceptionsValues.push([curRow[0], curRow[1], row])
}
delete exceptionsValues[index]
};
});
// next as a proof of concept I filtered on values you are values in the study report
let filteredExceptions = exceptionsValues.filter(row => row[0] == "Nico Vera" && row[2].indexOf("Kevin") >= 0);
// from here you might make find the indexOf the "~" character and split the string to extract the Assigned Analysts name. At this point you already have a row for each exception so it should be relatively easy to extract
// the proof of concept would need to be run as you create each row in your study report table.
// a few console statements to see results
console.log(exceptionsValues);
console.log(filteredExceptions);
}
在映射 table 中,我有一个 Exceptions
列,其中一些单元格包含具有多个自定义分隔符的字符串,即
Client1~Analyst1*Client2~Analyst2 etc
映射 Table:
+---------------+------------------+----------------------------------------------------+
| Project Owner | Assigned Analyst | Exceptions |
+---------------+------------------+----------------------------------------------------+
| Nico Vera | Maple | Globus Ltd~Walter Lobo*Kevin Kline~Sarah Wick*Monsanto Ltd~Ana Wier |
+---------------+------------------+----------------------------------------------------+
| Vijay Malya | Sonny | |
+---------------+------------------+----------------------------------------------------+
| Sam Tucker | Parvati | Mars~Sonapuri*China Blue~Mona Dsa |
+---------------+------------------+----------------------------------------------------+
| Pessy Shroff | Roy | Harbinger Ltd~Jose Silva*Theos Ltd~Jay Mills |
+---------------+------------------+----------------------------------------------------+
来自另一个FC Table
如下图:
FC Table:
+------+---------------+---------------+
| ID | Project Owner | Client |
+------+---------------+---------------+
| 1001 | Nico Vera | Globus Ltd |
+------+---------------+---------------+
| 1002 | Vijay Malya | Ventura |
+------+---------------+---------------+
| 1003 | Vijay Malya | Ventura |
+------+---------------+---------------+
| 1004 | Sam Tucker | Mocha Coffee |
+------+---------------+---------------+
| 1005 | Nico Vera | Roma Fashions |
+------+---------------+---------------+
| 1012 | Nico Vera | Monsanto Ltd |
+------+---------------+---------------+
| 1006 | Pessy Shroff | Murdoch Ltd |
+------+---------------+---------------+
| 1007 | Pessy Shroff | Harbinger Ltd |
+------+---------------+---------------+
| 1008 | Pessy Shroff | Theos Ltd |
+------+---------------+---------------+
| 1009 | Sam Tucker | Mars |
+------+---------------+---------------+
| 1013 | Sam Tucker | China Blue |
+------+---------------+---------------+
| 1010 | Nico Vera | Kevin Kline |
+------+---------------+---------------+
| 1014 | Nico Vera | Galettos |
+------+---------------+---------------+
每次,我都想将这些独特的项目行拉入另一个名为 Study Report
table 的历史记录 table 并且对于这些行中的每个 Project Owner
,检查任何异常在 Mappings
table 的 Exceptions
列中。
如果给出任何异常,那么对于任何 Client-Analyst
组合,我想添加客户的相应分析师,否则添加映射 table.
Assigned Analysts
中给出的默认分析师
学习报告Table:
+------+---------------+---------------+------------------+
| ID | Project Owner | Client | Assigned Analyst |
+------+---------------+---------------+------------------+
| 1001 | Nico Vera | Globus Ltd | Walter Lobo |
+------+---------------+---------------+------------------+
| 1002 | Vijay Malya | Ventura | Sonny |
+------+---------------+---------------+------------------+
| 1003 | Vijay Malya | Fountain Pens | Sonny |
+------+---------------+---------------+------------------+
| 1004 | Sam Tucker | Mocha Coffee | Parvati |
+------+---------------+---------------+------------------+
| 1005 | Nico Vera | Roma Fashions | Maple |
+------+---------------+---------------+------------------+
| 1012 | Nico Vera | Monsanto Ltd | Ana Wier |
+------+---------------+---------------+------------------+
| 1006 | Pessy Shroff | Murdoch Ltd | Roy |
+------+---------------+---------------+------------------+
| 1007 | Pessy Shroff | Harbinger Ltd | Jose Silva |
+------+---------------+---------------+------------------+
| 1008 | Pessy Shroff | Theos Ltd | Jay Mills |
+------+---------------+---------------+------------------+
| 1009 | Sam Tucker | Mars | Sonapuri |
+------+---------------+---------------+------------------+
| 1013 | Sam Tucker | China Blue | Mona Dsa |
+------+---------------+---------------+------------------+
| 1010 | Nico Vera | Kevin Kline | Sarah Wick |
+------+---------------+---------------+------------------+
| 1014 | Nico Vera | Galettos | Maple |
+------+---------------+---------------+------------------+
有谁知道如何拆分 Exceptions 列并使用 Typescript for Excel 执行此操作?任何帮助将不胜感激。
编辑:
....
// pick Opportunity Owner, FC Name, CD Team & Exceptions from Mapping sheet
let mapObj = MapTable.getRangeBetweenHeaderAndTotal().getValues()
.reduce((o, [a, b, c, d]) => Object.assign(o, { [a as string]: [b, c, d] }), {});
let existingIdsObj = StudyTable.getColumnByName("Study Number").getRangeBetweenHeaderAndTotal().getValues().reduce((o, [a]) => Object.assign(o, { [a as string]: true }), {});
let putValues:string[][] = FCTable.getRangeBetweenHeaderAndTotal().getValues().reduce((ar:string[][], [a, b, c, d, e, f, g, h, i, j, k, l,m]) => {
if (!existingIdsObj.hasOwnProperty(a as string)) {
// this is where i need help to define a loop for x
let x: string = (mapObj[d as string][2].trim().toString() !== '' && e.toString().toLowerCase().indexOf(mapObj[d as string][2].toString().toLowerCase().trim().split("~")[0]) !== -1) ? mapObj[d as string][2].trim().split("~")[1].toString() : mapObj[d as string][0].toString();
let y = h.toString();
switch (y) {
case "Active": y = "Open"; break;
case "Cancelled": y = "Cancelled"; break;
case "Completed": y = "Complete"; break;
default: y = "Check"; break;
}
ar.push([b, a, d, e, f, g, , , , , , y, , x, , , , c, k, m]);
}
return ar;
}, []);
// if new studies found, append them to Study Report sheet
if (putValues.length !== 0) {
StudyTable.addRows(-1, putValues);
}
}
...
我玩了一个 office 脚本,试图隔离拆分异常的任务,然后测试您在创建最终 table 时可能 运行 的过滤方法。我不是开发人员,但也许能让你更接近。也许这有帮助...
function main(workbook: ExcelScript.Workbook) {
// simple array of the mapping table used for testing purposes
let exceptionsValues = [
["Nico Vera", "Maple", "Globus Ltd~Walter Lobo * Kevin Kline~Sarah Wick * Monsanto Ltd~Ana Wier"],
["Vijay Malya", "Sonny", ""],
["Sam Tucker", "Parvati", "Mars~Sonapuri * China Blue~Mona Dsa"],
["Pessy Shroff", "Roy", "Harbinger Ltd~Jose Silva * Theos Ltd~Jay Mills"]
];
// augment the original mappings array by creating a new row for each exception (split on the "*") and deleting the row with the concatenated exceptions
exceptionsValues.map((curRow, index) => {
if (curRow[2].indexOf("*") > 0) {
let tempRows = curRow[2].split(" * ");
for (let row of tempRows) {
exceptionsValues.push([curRow[0], curRow[1], row])
}
delete exceptionsValues[index]
};
});
// next as a proof of concept I filtered on values you are values in the study report
let filteredExceptions = exceptionsValues.filter(row => row[0] == "Nico Vera" && row[2].indexOf("Kevin") >= 0);
// from here you might make find the indexOf the "~" character and split the string to extract the Assigned Analysts name. At this point you already have a row for each exception so it should be relatively easy to extract
// the proof of concept would need to be run as you create each row in your study report table.
// a few console statements to see results
console.log(exceptionsValues);
console.log(filteredExceptions);
}