wps对数据进行连接合并整理。如下图:
代码1:
function zip(...args){ let res=[], idx = 0, len = Math.max(...args.map(x => x.length)); while (idx < len){ res[idx] = args.map(x => x[idx]); idx += 1 } return res ; }
function textcombine(){ var arr=ThisWorkbook.Sheets.Item("Summary").Range("N2:U5").Value2; var brr=arr.map(function(item, index){ var a=item[7].toString().trim().split(","); var b=item[5].toString().trim().split(","); var list=zip(a,b); return [item[0].trim()+"/"+list.map(function(itm){return itm[0] +"~"+itm[1];})]}) ThisWorkbook.Sheets.Item("Summary").Range("V2").Resize(brr.length,1).Value2=brr }
上一段代码zip实现不同数组的元素交换重组。下一段常规套路比较容易理解:
function txtcombine(){ var arr=ThisWorkbook.Sheets.Item("Summary").Range("N2:U5").Value2; var brr=new Array(arr.length) arr.forEach(function(item,index){ var a=item[7].toString().trim().split(","); var b=item[5].toString().trim().split(","); brr[index]=""; for(var i=0;i<a.length;i++){ brr[index]+=","+a[i] +"~"+b[i];} brr[index]=[item[0].trim()+"/"+brr[index].substring(1)];}) ThisWorkbook.Sheets.Item("Summary").Range("V2").Resize(brr.length,1).Value2=brr }