|
JSA代码,由于单位办公软件换WPS,不能用Office,现阶段由VBA全面转JSA
- function 数据连接(){
- let arr=Range("a3:k9").Value2;
- let obj={},key;
- let [bt1,bt2]=[arr[0],arr[1]];
- for (let i=3;i<bt1.length-1;i++){
- if (bt1[i]!=null) key=bt1[i];
- let temp=obj[key]=obj[key] || [];
- temp.push([bt2[i],i]);
- }
- let res=[],k=-1;
- arr.slice(2).forEach(x=>{
- let s1=`${x[0]}、${x[1]}:给客户${x[2]}售出共${x[x.length-1]}kg,`;
- let tp=[];
- for (let key in obj){
- let temp=obj[key];
- let n=temp[temp.length-1][1];
- if (x[n]==null) continue;
- let s2=`${key}${x[n]}kg(`;
- let s3=temp.reduce((ar,[a,b])=>(a!="小计" && x[b]!=null?ar.push(`${a}${x[b]}kg`):null,ar),[]).join("、") + ")";
- tp.push(s2+s3);
- }
- res[++k]=[s1 + tp.join(";") + "。"];
- });
- Range("l5").Resize(res.length,1).Value2=res;
- }
复制代码 |
|