谷歌应用程序脚本中的getValue()和getDisplayValue()之间的区别 [英] Difference between getValue() and getDisplayValue() on google app script
问题描述
Google应用脚本中的 range.getDisplayValue()
和 range.getValue()
有什么区别?
What is the difference of range.getDisplayValue()
and range.getValue()
on Google app script?
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var val1 = sheet.getRange(7,5).getDisplayValue();
var val2 = sheet.getRange(7,5).getValue();
Val1
和 Val2
都是相同的。
推荐答案
getDisplayValue
返回你在屏幕上看到的值,因此总是一个字符串,而 getValue
返回下面的值,因此是一个对象。如果范围内有文字,它可能是一个字符串。
getDisplayValue
returns the value as you see in the screen, therefore always a string, while getValue
returns the value underneath, therefore an object. Which may be a string if the range has text in it.
如果范围内有数字或日期,则区别更加清晰。特别是如果电子表格区域设置使用逗号作为小数点分隔符来格式化数字,或者如果您在范围中设置自定义格式。
The difference is more clear if the range has numbers or dates in it. Specially if the spreadsheet locale formats the numbers with commas as decimal separators or if you set custom formats in your ranges.
这篇关于谷歌应用程序脚本中的getValue()和getDisplayValue()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!