简体   繁体   中英

How to update a Google spreadsheet from a webpage

I am working on a website that uses a Google spreadsheet like an SQL database (did so by publishing the csv file to the web, and reading that as a multidimensional array). Now, I have come to the issue of updating fields in the spreadsheet when a user updates their information on the site. Does anyone have any suggestions on how best to do this? Could I do it with a Google Apps Script, triggered when going to a certain webpage? Or even just straight up PHP/javascript/whatever else?

I'm just looking for general strategies for how to go about this, any information would be very helpful!

I would think if you created a Google Form for them to update their info, and set a script to run onFormSubmit(), you could load the "database" and update the values from the information they submitted. To load the database, you'd need its ID, and then you'd use spreadsheet = SpreadsheetApp.openByID("theID"); Once you opened it, you'd need to get the cells to edit. The trick would be finding them. If you iterate through the rows until you find some key value to match the user (an id# entered in the form?) Then you could change the value of each cell in that row to match the new values.

This should be very straightforward and simple...

You said you read data from a CSV file coming from a spreadsheet into an multidimentional array...

Well, simply skip that step, create the array directly from the spreadsheet with getDataRange.getValues() , process data inside the 2D array and each time you need to validate the changes use getRange(1,1,array.length,array[0].length).setValues(array) and that should be it !

This is how I usually work and it's pretty easy and efficient ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM