setFormulas won't skip empty array elements, over-writes values

后端 未结 2 1895
孤城傲影
孤城傲影 2021-01-19 06:28

Consider the code below: it sets values then sets functions across a range, however it overwrites the values that were set.

function test() {
  var ss = Spre         


        
相关标签:
2条回答
  • 2021-01-19 06:47

    This certainly explains why setting values overwrites formulas, but wouldn't it be nicer if there were a way to getValuesandFormulas together into an array?

    If (like me) you were distracted into getValues and getFormulas, realise that you can use copyTo between ranges to copy the overall contents!

    0 讨论(0)
  • 2021-01-19 06:48

    I think the problem can be largely mitigated by the fact that setValues() can be used to set formulae.

      var range = ss.getRange("A1:B2");
      var values = range.getValues();
    
      // process the array, eg values[0][0] = "=42";
    
      range.setValues();
    
    0 讨论(0)
提交回复
热议问题