I searched the internet and I can't find a response to this nor the documentation for it. I need to dynamically generate Google forms questions with data from a Google spreadsheet using app script, but I don't know how to reference and read a spreadsheet.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- How can I force all files in a folder to be owned
In your spreadsheet select
Tools > Script Editor
and adapt this to your needs:To debug, select the script in the combobox and click either "play" or "debug". The first time you will have to give it permissions to interact with your spreadsheet and form.
Once you are satisfied with the result, in the editor select
Resources > Triggers for the active project
and add this method to be triggered with any modification on the spreadsheet (on change, not on edit).After this, your form options will be changed in real time after any change in your spreadsheet.
It's pretty straightforward, see here: https://developers.google.com/apps-script/guides/sheets#reading
You just need to open the sheet by its doc key, select the data and read the cells as a JS object.
Here is an example which works for me, pls kindly check:
You can get your sheet Id from url, for example:
Let me know if you have any further questions.