从HTML页面更改电子表格中的值 [英] Changing values in a spreadsheet from HTML page

查看:134
本文介绍了从HTML页面更改电子表格中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难用自定义GUI创建HTML页面,该页面显示可编辑的电子表格中的数据.

I am having difficulties creating an HTML page with a custom GUI that displays data from a spreadsheet that can be edited.

一个简单的示例,假设我们在电子表格"Sheet1"中的位置"A1"中有一个值,它说"Hello",就是这样.然后在网页上出现一个文本字段,其中"Hello"已设置为该文本输入字段,因此现在您可以将文本更改为"Ohoy",并且在输入字段旁边有一个按钮,显示"Save".然后将电子表格"A1"中的相应单元格设置为在输入字段"Ohoy"中输入的内容

A simple example, let's say we have one value in our spreadsheet "Sheet1" in the location "A1" and it Says "Hello", that's it. Then on the webpage a textfield appears where the "Hello" has been set to that text-input field, so now you can change the text to let's say "Ohoy" and next to the input field there is a button that says "Save" and then it set's the corresponding cell in the spreadsheet "A1" to what is entered in the input field, "Ohoy" in this case

有人可以帮助我吗?我读过人们已经做过的事情,只是想不出它的确切编码.

Anyone who could help me with this? I have read that people have done it, I just can't quite figure out the ecact coding of it.

推荐答案

您将需要在appscript中创建一个函数以及html以显示输入字段.

You will need to create a function in appscript, as well as the html to display the input field.

在GS(Google AppScript)中,您将需要一个函数来显示HTML,以及另一个函数来设置从输入字段(editContents)发送的值. 这是gs的代码:

In GS (Google AppScript), you will need a function to display the HTML, as well as another one to set the values sent from the input field (editContents). Here is the code for the gs:

function doGet()
{
  return HtmlService.createHtmlOutputFromFile('Index')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

function editContents(text)
{
  var ss = SpreadsheetApp.openById("ID_of_your_Spreadsheet");
  var activeCell = ss.getActiveCell();
  activeCell.setValue(text);
}

在HTML中,您只需要输入和一个按钮.使用google.script.run访问gs中定义的功能.

In your Html, you only need the input and a button. Use google.script.run to access the functions defined in gs.

<html>
  <body>
  <input type="text" name="text" id='txtEdit'><br>
  <input type="button" value="Save"
  onclick="google.script.run.editContents(document.getElementById('txtEdit').value)">
  </body>
</html>

这篇关于从HTML页面更改电子表格中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆