【问题标题】:Google Sheet Sidebar Data Entry Sidebar Form Pass Value谷歌表格侧边栏数据输入侧边栏表单传递值
【发布时间】:2020-04-19 10:03:52
【问题描述】:

当我点击按钮数据提交时。 我正在使用这段代码,你能帮我解决这个问题吗

代码.gs

function onOpen() {
  SpreadsheetApp
      .getUi()
      .createMenu('Sidebar')
      .addItem('Contact Form', 'showSidebar')
      .addToUi();
}

function showSidebar() {
  var html = HtmlService
      .createTemplateFromFile('sidebar')
      .evaluate()
      .setTitle('Contact Form');
  SpreadsheetApp.getUi()
      .showSidebar(html);
}

和sidebar.html

<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form id="contact">

<h3>First Name</h3>
<input type="text" name="firstname">   

<h3>Phone Number</h3>
<input type="text" name="phone">

<a href="#" onClick="return false;" class="fltr-button  animate">Submit</a>

</form>
</body>
</html>

【问题讨论】:

  • 嗨@ManishSinghal,欢迎来到StackOverFlow。请参考此stackoverflow.help/support/solutions/articles/…
  • 而且 当我点击按钮数据提交时 对我来说似乎不完整。请告诉我们您面临的问题,以便我们能够更好地帮助您。

标签: google-apps-script google-sheets


【解决方案1】:
function showSideBar() {
  const html='<form><input type="text" name="firstname" placeholder="First Name" /><input type="text" name="phone" placeholder="Phone Number" /><br /><input type="button" value="Submit" onClick="google.script.run.processForm(this.parentNode);" /></form>';
  SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutput(html));
}

function processForm(obj) {
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  sh.appendRow([obj.firstname,obj.phone])
}

动画:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    相关资源
    最近更新 更多