Sidebar in google sheets using apps script not working

丶灬走出姿态 提交于 2021-01-07 02:45:40

问题


I'm trying to build a sidebar in my google sheet and assign to it a script to send an emails. The problem is the title and close button displays correctly but the content of the sidebar is not displaying and it gives an error : "n-sf2kk5ynt6qhvo6tzp2uamld3a63ce7qvtsloby-0lu-script.googleusercontent.com took too long to respond."

This is the code I used:

  1. interface.gs
function onOpen() {
  SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
      .createMenu('Control Panel')
      .addItem('Email', 'showEmail')
      .addToUi();
}

function showEmail() {
  var html = HtmlService.createHtmlOutputFromFile('Page')
      .setTitle('Email Panel')
      .setWidth(300);
  SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
      .showSidebar(html);
}

2.Page.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <div>Hello World!</div>
    <input type="button" value="Close" onclick="google.script.host.close()" />

  </body>
</html>


回答1:


The issue is solved now, weirdly it was a problem with my router so resetting the router solved it thanks for all the help.




回答2:


Here's a simple sidebar script to send and email

function sendemaildialog() {
  var html='<html><body>';
  html+='<form><input type="text" name="email" placeholder="Email Address" /><br/><input type="text" name="subject" placeholder="Subject"/>';
  html+='<br/><textarea rows="4" cols="30" name="message"></textarea><br/><input type="button" value="Send" onclick="google.script.run.sendEmail(this.parentNode);"/></form>';
  html+='</body></html>';
  SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutput(html));
}

function sendEmail(obj) {
  GmailApp.sendEmail(obj.email, obj.subject, obj.message);
}


来源:https://stackoverflow.com/questions/63564503/sidebar-in-google-sheets-using-apps-script-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!