【问题标题】:How to copy value from one column to another on Google Sheets?如何在 Google 表格上将值从一列复制到另一列?
【发布时间】:2020-08-15 09:02:32
【问题描述】:

是否有任何公式或脚本可以仅将值(而不是公式)从一列复制到另一列?我不想使用 CTRL + SHIFT + V 因为我需要它是自动的。例如:

Column A  Column B
Value1
Value2
Value3

A 列的所有值都是用数组公式计算的,我需要每次 A 列有新记录时,值都会永远传递到 B 列,所以如果 A 列中的值或公式被删除,则复制的值仍然在 B 列中,是否可以这样做?

请帮忙!

【问题讨论】:

  • 可以使用脚本或宏
  • 谢谢,是的,我认为是这样,但我找不到可以做到这一点的脚本
  • 你可以做一个触发器来检查新值。它可以每隔几分钟、几小时或几天运行一次。这符合您的需求吗?

标签: javascript google-apps-script google-sheets scripting


【解决方案1】:

你想要

  • 将 google 表格上的一列中的值复制到同一个 google 表格上的另一列

如果我的理解是正确的,那么这个答案呢?请将此视为解决问题的多种可能方法之一。

流程:
1.获取活动表 2.获取活动范围(列) 3. 将值粘贴到范围(列)中

示例脚本:

function copyvalues() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet1');
  const rg = sh.getRange(1,1,sh.getLastRow()); //Explore the various getRange functions
  const va = rg.getValues();  //Explore Arrays if you are not familiar with it
  va.forEach(function(r,i){
    sh.getRange(i+1,2).setValues(r[0]).setNumberFormat('#,##0.00');  //Use setNumberFormat if you need to format your values with two decimal places and thousands separator (if not already done so)
  })
}

参考:

【讨论】:

  • 您还应该使用setValues() 而不是setValue()。循环数组>创建一个带有修改的新输出数组或就地修改输入数组>在循环外设置修改后的数组
猜你喜欢
  • 1970-01-01
  • 2012-02-18
  • 2021-12-12
  • 1970-01-01
  • 1970-01-01
  • 2013-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多