Skip to content Skip to sidebar Skip to footer

Changing Values In A Spreadsheet From Html Page

I am having difficulties creating an HTML page with a custom GUI that displays data from a spreadsheet that can be edited. A simple example, let's say we have one value in our spr

Solution 1:

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

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);
}

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>

Post a Comment for "Changing Values In A Spreadsheet From Html Page"