Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

html - Running a web app from a google sheet menu click

I am trying to run a webapp from a spreadsheet when the user clicks a menu item. The code is below. My problem is I get this error message

We're sorry, a server error occurred. Please wait a bit and try again

I have deployed it as a webapp and when I do the test deployment all is good but if I try and run it from the spreadsheet I get the above. What am I doing wrong?

function onOpen() {
  var ss = SpreadsheetApp.getActive();
  var menuEntries = [{name: "xxx", functionName: "doGet"}];
  ss.addMenu("yyy", menuEntries);
}

function doGet()
{
   var ss = SpreadsheetApp.getActive();
  
      let HTMLString = "<style> h1,p {font-family: 'Helvitica', 'Arial'}</style>"
                    + "<h1>Hello World!</h1>"
                    + "<p>Welcome to the Web App";
    HTMLOutput = HtmlService.createHtmlOutput(HTMLString);
    return HTMLOutput
};
question from:https://stackoverflow.com/questions/65909791/running-a-web-app-from-a-google-sheet-menu-click

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's not possible to directly run a web app from a custom menu but yo might open a dialog with client-side code that will open your web app on a new window. See Google Apps Script to open a URL for details.

Explanation

doGet is a reserved function name that will be triggered when the web app url gets an HTTP GET call. While it can be called from a custom menu, it's not expecting a "return" from the function called, so there is no place available to render the return of your doGet function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...