Google Sheets Integration

cms

#1

I am having some trouble integrating Google sheets into my application.

I would like to use Google Sheets for two use cases:
1. To fill in information for responses
2. To provide links for audio streaming

In reference to the first use case, I am having trouble selecting cells because the key I’m using is a date. This means that when I make the reference a nested object like this:

this.$cms.Sheet1.07-02.Object1;

the code fails to compile. I’ve also tried using template literals but this also fails to compile. It would look like this:
var today = '07-02'
this.$cms.Sheet1.${today}.Object1

Due to the syntax, I cannot call nested objects. I would like to keep the date as a key so users can input the date as a parameter/slot and the code can use the given date to search the sheet. Would something like this be possible?

I would like to use the same technique to update a link for an audio file that changes weekly. Instead of manually updating the code every week, calling the sheet would be more efficient and simple. Again, would it be possible to use something like template literals to achieve this?

Appreciate the help!


#2

You could use the bracket notation and do something like this:

const dateKey = '07-02';
const someValue = this.$cms.Sheet1[dateKey].Object1;

#3

Bracket notation works like a dream. Thanks Ruben!