【问题标题】:google sheet : split the long data output - from single column into multiple column谷歌表:拆分长数据输出 - 从单列到多列
【发布时间】:2021-09-01 01:49:46
【问题描述】:

我有一张包含大量数据的大表格。我使用 filter() 或 query() 或 vlookup() 从该表中提取具有特定条件的列。然后结果将是具有长数据/行的单列。例如:输出是单列,有 300 行,但我想要每列 50 行。是否有任何方法将它们自动拆分为 6 列(每列包含 50 行)而不是单列包含 300 行。

谢谢

【问题讨论】:

标签: google-sheets


【解决方案1】:

Apps 脚本解决方案

虽然这可以通过公式来实现,但即使player0's brilliant and complex function 对它可以处理的输入量也有上限。对我来说,这似乎是 Apps Script 自定义函数的完美场景。

function divideColumn(input, numberToSplit){
  const length = input.length
  // The input it receives in the form of a two dimensional array. This just makes it one dimensional for convenience
  const flattenedInput = input.flat()
  // Getting the number of columns that will be filled
  const numberOfColumns = Math.ceil(length / 50)

  // Building the 2D array output with the specified number of rows.
  const output = []
  for (let i=0; i!= numberToSplit; i++){
    output.push([])
  }

  // Building an intermediate 2D array of the columns
  const columns = []

  for (let j=0; j!=numberOfColumns; j++){
    const lowerBound = numberToSplit * j
    let upperBound;
    if (j != numberOfColumns - 1) {
      upperBound = numberToSplit * (j + 1)
    } else {
      upperBound = -1
    }
    const col = flattenedInput.slice(lowerBound, upperBound)
    columns.push(col)
  }

  // Transposing the intermediate array into the final output format
  columns.forEach((col) => {
    col.forEach((val, idx) => {
      output[idx].push(val)
    })
  })

  return output
}

在使用中你可以这样做:

限制

它只适用于单列。

安装说明

菜单 > 工具 > 脚本编辑器

将函数传递到那里并保存。

那你应该准备好了!

参考

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-12
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 2019-09-18
    • 1970-01-01
    • 2018-10-22
    • 1970-01-01
    相关资源
    最近更新 更多