【问题标题】:getValues and setValues with different ranges具有不同范围的 getValues 和 setValues
【发布时间】:2019-07-26 08:57:06
【问题描述】:

我有一个 Google 脚本,可以在按下按钮时设置从工作表 B 到工作表 A 的特定范围的值。

我的代码可以运行,但我猜由于 getValue/setValue 的大量使用,它需要大约 40 秒。

下面看到的代码只是一个sn-p。如图所示,它会这样持续大约四次。

我已经有了一个很好的解决方案,可以从一个大范围内复制值(比如 A1:Z30 通过循环,但我无法在这里找到解决这个问题的方法。

非常感谢您的支持。提前谢谢你。

ratenprogrammmain.getRange("E1:E18").setValues(vorlage.getRange("E13:E30").getValues());

ratenprogrammmain.getRange("B2").setValue(vorlage.getRange("B14").getValue());

ratenprogrammmain.getRange("B5").setValue(vorlage.getRange("B17").getValue());

ratenprogrammmain.getRange("A21").setValue(vorlage.getRange("A33").getValue());

ratenprogrammmain.getRange("B25").setValue(vorlage.getRange("B37").getValue());

ratenprogrammmain.getRange("A28:G33").setValues(vorlage.getRange("A40:G45").getValues());

ratenprogrammmain.getRange("H35").setValue(vorlage.getRange("H47").getValue());

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    如何让你的代码更高效的三个想法

    【讨论】:

    • copyTo() 方法对我帮助很大。在我的情况下,它比 setValue() 资源效率高得多。非常感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 2013-03-16
    • 2016-02-03
    相关资源
    最近更新 更多