Build range with string

狂风中的少年 提交于 2021-02-17 06:25:08

问题


I have this statement:

var destinationRange = destinationSheet.getRange("D26:E39");

and want to replace it with

var destinationRange = destinationSheet.getRange(daGrowaRange);

The reason I want to use daGrowaRange is not just cause da name, but that the range is not always the same.

  • D is a fixed constant value and never changes
  • E is a fixed constant value and never changes

BUT

  • 26 is dynamic and changes and
  • 39 is an offset based on the 26 (in this case 13 so 39 = 26+13, but the 13 is a variable value also).

I am sure that I could put this together in some ugly ass way, but I am sick of looking at my crappy code and want to learn how you crackz out there make it nice.

Thank you


回答1:


You can use Template literals to accomplish this task:

const dValue = 26;
const eValue = dValue + 13;
const daGrowaRange = `D${dValue}:E${eValue}`;
const destinationRange = destinationSheet.getRange(daGrowaRange);


来源:https://stackoverflow.com/questions/63458072/build-range-with-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!