Difference between getValue () and getDisplayValue () in google app script

What is the difference range.getDisplayValue() and range.getValue() in a Google script application?

 var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var val1 = sheet.getRange(7,5).getDisplayValue(); var val2 = sheet.getRange(7,5).getValue(); 

Val1 and Val2 same.

+6
source share
2 answers

getDisplayValue returns a value, as you see on the screen, therefore it is always a string, and getValue returns a value at the bottom, therefore an object. Which can be a string if the range has text in it.

The difference is more clear if the range has numbers or dates in it. Specifically, if the spreadsheet table locale formats numbers with commas as decimal separators, or if you set custom formats in your ranges.

+7
source

To add more to Enrique's explanation, here is an example from my experience.

I have a column in which I entered time in IST

 IST -------- 2:00 AM 

And when I get the value of this column,

 var myTime = range.getValue(); 

who actually came back

 Sat Dec 30 1899 01:36:40 GMT+0530 (IST) 

But range.getDisplayValue () solved my problem, which returned what I entered at 2:00 in the morning.

+2
source

All Articles