• Got Sheet
  • Posts
  • Using Apps Script to Get Values

Using Apps Script to Get Values

Automate Your Way Out of Typos

CODING & SPREADSHEETS
All The Values and How to Get ‘em

Since last we spoke I’ve…

  1. Begun a navy seal burpee workout for when I don’t brave the elements to run.

  2. Pulled down a couple novels to revisit…before finishing the one I’m currently reading.

  3. Started reading the Fellowship of the Ring with my oldest son.

Now to the sheets…

When using Apps Script, you often will need to get values from the cells in your spreadsheet. There are two distinct built-in methods to help with this: getValues() and getDisplayValues().

For each of these, there is a singular version i.e. getValue() and getDisplayValue() as well as the plural version.

The plural version is what I use most because it allows you to grab values across a range rather than in just one cell.

What I want to look at, though, is the difference between these two. This was new info for me today:

getValues()

This is what I typically use. As you may have guessed, calling this will simply get you the values in a range of cells. It will return a two-dimensional array of values which can be Number, Boolean, Date or String depending on what is in the cell.

let range = sheet.getRangeByName('dates');
let getValues = range.getValues();

getDisplayValues()

This will do the same thing, only it will only return an array of strings. So whatever is displayed in the cell is returned as a string. Below is an example of the same two date objects logged using getValues() vs getDisplayValues():

let range = sheet.getRangeByName('dates');
let displayValues = range.getDisplayValues();

If you want to follow along in the demo sheet I made, here it is.

And the video walkthrough I did is below 👇

Thank you so much!

It means a lot that you’ve read this, and I hope it’s informed and/or entertained you for a few moments today!

Would love to say hi. Here are the best places to find me:

✉️ LinkedIn
📺️ YouTube

Ways I can help:

  • View my spreadsheet and creative products on my Gumroad store.

  • Need a powerful automation tool for Google Sheets? Try Coefficient to automatically import data and sync with your business systems.

  • Hire an expert to help complete your next Google Sheets, Apps Script or Google Workplace project.

Reply

or to participate.