最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - google apps script counting characters in a cell - Stack Overflow

programmeradmin2浏览0评论

I am trying to find a way to adjust a merged cell group to show all text characters that were contained in the first cell when merged. I thought there would be a simple way to count the number of characters in that first cell and then I can adjust the height of a cell or cells by developing a formula (such as add .2 for each 30 characters).

I am using the following code to try and count the characters:

var tempValue;
var tempCount = 0;

    tempValue = sprintSheet.getRange("D3").getDisplayValue();
    tempCount = tempValue.length();

Unfortunately, I get the following error on the last line:

TypeError: Cannot call property length in object

I can't seem to make the transition from range / value to text to use the length property.

I am trying to find a way to adjust a merged cell group to show all text characters that were contained in the first cell when merged. I thought there would be a simple way to count the number of characters in that first cell and then I can adjust the height of a cell or cells by developing a formula (such as add .2 for each 30 characters).

I am using the following code to try and count the characters:

var tempValue;
var tempCount = 0;

    tempValue = sprintSheet.getRange("D3").getDisplayValue();
    tempCount = tempValue.length();

Unfortunately, I get the following error on the last line:

TypeError: Cannot call property length in object

I can't seem to make the transition from range / value to text to use the length property.

Share edited Aug 1, 2017 at 0:11 Wicket 38.8k9 gold badges80 silver badges195 bronze badges asked Jul 31, 2017 at 21:13 TC LawrenceTC Lawrence 1431 gold badge3 silver badges5 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Short answer

Use tempCount = tempValue.length instead of tempCount = tempValue.length();

Explanation

Google Apps Script is based on JavaScript. The getDisplayValue() returns an a JavaScript string primitive. A primitive data type can use the the length property, and its called by using .length, (note that parenthesis are not used).

References

  • https://developers.google./apps-script/overview

The string length is available as a property rather than as a function call.

https://www.w3schools./jsref/jsref_length_string.asp

tempCount = tempValue.length;
发布评论

评论列表(0)

  1. 暂无评论