简体   繁体   English

如何从网页更新Google电子表格

[英]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). 我正在一个使用Google电子表格(如SQL数据库)的网站上工作(这样做是通过将csv文件发布到网络上,并将其作为多维数组读取)。 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? 我可以使用转到某个网页时触发的Google Apps脚本来执行此操作吗? Or even just straight up PHP/javascript/whatever else? 甚至只是直接整理PHP / javascript /其他内容?

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. 我想如果您为他们创建了一个Google表单来更新他们的信息,并设置了一个脚本运行onFormSubmit(),则可以加载“数据库”并从他们提交的信息中更新值。 To load the database, you'd need its ID, and then you'd use spreadsheet = SpreadsheetApp.openByID("theID"); 要加载数据库,您需要它的ID,然后使用电子表格= 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. 如果您遍历行直到找到与用户匹配的某个键值(在表格中输入的id#?),然后可以更改该行中每个单元格的值以匹配新值。

This should be very straightforward and simple... 这应该非常简单明了...

You said you read data from a CSV file coming from a spreadsheet into an multidimentional array... 您说您是从CSV文件中读取数据,该数据是从电子表格导入到多维数组中的...

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 ! 好吧,只需跳过这一步,直接使用getDataRange.getValues()从电子表格创建数组,在2D数组中处理数据,每次需要验证更改时,都使用getRange(1,1,array.length,array[0].length).setValues(array)就是这样!

This is how I usually work and it's pretty easy and efficient ;) 这就是我通常的工作方式,非常简单有效;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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