0

在映射表中,我有一Exceptions列,其中一些单元格包含具有多个自定义分隔符的字符串,即,

Client1~Analyst1*Client2~Analyst2 etc

映射表:

+---------------+------------------+----------------------------------------------------+
| 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表:

+------+---------------+---------------+
| 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 Reporttable 的历史表中,并且对于这些行中的每一行,检查表列中的Project Owner任何异常。如果给出任何例外,那么对于任何组合,我想添加客户的相应分析师,否则添加映射表中给出的默认分析师。ExceptionsMappingsClient-AnalystAssigned Analysts

研究报告表:

+------+---------------+---------------+------------------+
| 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);
  }

}
...
4

1 回答 1

1

我使用了一个办公室脚本,试图隔离拆分异常的任务,然后测试一个过滤器方法,您可能会在创建决赛桌时运行该过滤器方法。我不是开发人员,但也许可以让你更接近。也许这有帮助......

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);
}
于 2022-02-03T07:21:44.043 回答