如何使用Google Apps脚本组合2个替换Array1元素的多维数组与Arrray2的元素组合?

发布于 2025-02-08 03:51:48 字数 1390 浏览 1 评论 0原文

我一直在努力完成这项工作,而没有任何成功。

这是要放置没有公式的数据。因此,想法是合并这两个阵列并立即将其放置。

array1 = 
[
 ["item1","","","details1"], 
 ["item2","","","details2"], 
]

该数组包含从将要放置传入数据的目的地范围中获取的公式,但是由于需要公式,

array2 = 
[
 ["","=iferror(VLOOKUP(A63,'Client List'!$A$1:$S,19,0),"")","=iferror(if(B63="Agency", 'Reference Info'!$C$7, VLOOKUP(A63,'Client List'!$A$1:$T,20,0)),"")",""], 
 ["","=iferror(VLOOKUP(A64,'Client List'!$A$1:$S,19,0),"")","=iferror(if(B64="Agency", 'Reference Info'!$C$7, VLOOKUP(A64,'Client List'!$A$1:$T,20,0)),"")",""]
]

预期结果

array2 = 
[
 ["item1","=iferror(VLOOKUP(A63,'Client List'!$A$1:$S,19,0),"")","=iferror(if(B63="Agency", 'Reference Info'!$C$7, VLOOKUP(A63,'Client List'!$A$1:$T,20,0)),"")","details1"], 
 ["item2","=iferror(VLOOKUP(A64,'Client List'!$A$1:$S,19,0),"")","=iferror(if(B64="Agency", 'Reference Info'!$C$7, VLOOKUP(A64,'Client List'!$A$1:$T,20,0)),"")","details2"]
]

这是我的尝试,但我似乎无法达到底部它:

 let finalRowValues = []
  for (let a = 0; a < array2.length; a++) {
    for (let n = 0; n < array1.length; n++) {
      array2[a].forEach(function(value, j){
        if(value == '' && array1[n][j] != ''){
          finalRowValues.push(array1[n][j])
        } else {
          finalRowValues.push(value)
        }
      })
    }
  }

I've been trying to get this one done, without any success.

This is data to be placed where there is no formula. So, the idea is to merge these two arrays and place it at once.

array1 = 
[
 ["item1","","","details1"], 
 ["item2","","","details2"], 
]

This array contains formulas grabbed from the destination range where the incoming data will be placed, but since the formulas are needed,

array2 = 
[
 ["","=iferror(VLOOKUP(A63,'Client List'!$A$1:$S,19,0),"")","=iferror(if(B63="Agency", 'Reference Info'!$C$7, VLOOKUP(A63,'Client List'!$A$1:$T,20,0)),"")",""], 
 ["","=iferror(VLOOKUP(A64,'Client List'!$A$1:$S,19,0),"")","=iferror(if(B64="Agency", 'Reference Info'!$C$7, VLOOKUP(A64,'Client List'!$A$1:$T,20,0)),"")",""]
]

Expected Result

array2 = 
[
 ["item1","=iferror(VLOOKUP(A63,'Client List'!$A$1:$S,19,0),"")","=iferror(if(B63="Agency", 'Reference Info'!$C$7, VLOOKUP(A63,'Client List'!$A$1:$T,20,0)),"")","details1"], 
 ["item2","=iferror(VLOOKUP(A64,'Client List'!$A$1:$S,19,0),"")","=iferror(if(B64="Agency", 'Reference Info'!$C$7, VLOOKUP(A64,'Client List'!$A$1:$T,20,0)),"")","details2"]
]

This is my attempt, but I can't seem to get to the bottom of it:

 let finalRowValues = []
  for (let a = 0; a < array2.length; a++) {
    for (let n = 0; n < array1.length; n++) {
      array2[a].forEach(function(value, j){
        if(value == '' && array1[n][j] != ''){
          finalRowValues.push(array1[n][j])
        } else {
          finalRowValues.push(value)
        }
      })
    }
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沐歌 2025-02-15 03:51:48

如果没有值,则是插入公式的简单方法:

function myFunction() {

  const formulas = [[]]
  const values = [[]]

  return values.map((row, rowIndex) => row.map((col, colIndex) => col || formulas[rowIndex][colIndex]))

}

Here's a simple way to insert the formula if no value is present:

function myFunction() {

  const formulas = [[]]
  const values = [[]]

  return values.map((row, rowIndex) => row.map((col, colIndex) => col || formulas[rowIndex][colIndex]))

}
写给空气的情书 2025-02-15 03:51:48

这是这样做的方法之一。

const array1 = 
[
 ["item1","","","details1"], 
 ["item2","","","details2"], 
]

const array2 = 
[
 ["",`=iferror(VLOOKUP(A63,'Client List'!$A$1:$S,19,0),"")`,`=iferror(if(B63="Agency", 'Reference Info'!$C$7, VLOOKUP(A63,'Client List'!$A$1:$T,20,0)),"")`,""], 
 ["",`=iferror(VLOOKUP(A64,'Client List'!$A$1:$S,19,0),"")`,`=iferror(if(B64="Agency", 'Reference Info'!$C$7, VLOOKUP(A64,'Client List'!$A$1:$T,20,0)),"")`,""]
]

const result = array1.map((arr, i) => {
  const [place1, place2, place3, place4] = arr
  if(place2 == ""){
    return [place1, array2[i][1], array2[i][2],place4]
  } else {
    return arr
  }
})

console.log(result)

This is one of the way's to do it.

const array1 = 
[
 ["item1","","","details1"], 
 ["item2","","","details2"], 
]

const array2 = 
[
 ["",`=iferror(VLOOKUP(A63,'Client List'!$A$1:$S,19,0),"")`,`=iferror(if(B63="Agency", 'Reference Info'!$C$7, VLOOKUP(A63,'Client List'!$A$1:$T,20,0)),"")`,""], 
 ["",`=iferror(VLOOKUP(A64,'Client List'!$A$1:$S,19,0),"")`,`=iferror(if(B64="Agency", 'Reference Info'!$C$7, VLOOKUP(A64,'Client List'!$A$1:$T,20,0)),"")`,""]
]

const result = array1.map((arr, i) => {
  const [place1, place2, place3, place4] = arr
  if(place2 == ""){
    return [place1, array2[i][1], array2[i][2],place4]
  } else {
    return arr
  }
})

console.log(result)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文