scripting - google apps script - batch setValues() on Sheet -
in order optimize code, i'm trying batch updates. instead of calling setvalues() on loop, want store data in array, setvalues() once after loop. however, can't make work:
var tempvaluesarr= []; var ctr = 0; ....{ //there 1 row needed every second sheet, data @ 2nd //row 6 columns var secondsheetrange = secondsheet.getrange(2, 1, 1, 6); tempvaluesarr.push(secondsheetrange.getvalues()); ctr++; } //finally, copy these tempvalues @ sheet, starting @ second row var anothersheetrange = anothersheet.getrange(2, 1, ctr, 6); anothersheetrange .setvalues(tempvaluesarr);
here's error i'm getting:
incorrect range width, 1 should 6
thanks!
i think issue pushing 2d array ( [[cella2, cellb2], [cella3, cellb3]]
) 1d array ( []
), leaving 3d array ( [[[cella2, cellb2], [cella3, cellb3]]]
).
to use setvalues need 2d ( [[cella2, cellb2], [cella3, cellb3]]
- 2 rows or [[cella2, cellb2]]
- 1 row ) array of values.
try this, push first 1d array ( [cella2, cellb2, cellc2]
) range empty array created @ start. more information here.
tempvaluesarr.push(secondsheetrange.getvalues()[0])
Comments
Post a Comment