Hello to all. There is a GoogleSheet (output) , on which from under the client you need to put down the number 15. I have compiled a program but it just does nothing. Programs consist of: Code.gs (server-side code), Client.js.html (client-side code), Main.js.html (works after loading the document), Index.html (entry point). What could be the error? Tell me please.

Code.gs

 function onOpen(e) { SpreadsheetApp.getUi() .createMenu('Value') .addItem('Estimate', 'tryExchange') .addToUi(); } function putValuesRange(value) { var ss = SpreadsheetApp.getActiveSpreadsheet(); var outputSheet = ss.getSheetByName('output'); return outputSheet.getRange(5, 5).setValue(value); } function tryExchange() { HtmlService.createTemplateFromFile('Index.html') .evaluate(); } 

Client.js.html

 <script> var Client = (function(client) { client.putData = function(v) { google.script.run .putValuesRange(v); }; return client; })(Client || {}); </script> 

Main.js.html

 <script> window.onload = function() { Client.putData(15); } </script> 

Index.html

 <!DOCTYPE html> <html> <head> <base target="_top"> </head> <body> <?!=HtmlService.createHtmlOutputFromFile('Client.js').getContent();?> <?!=HtmlService.createHtmlOutputFromFile('Main.js').getContent();?> </body> </html> 
  • There is no need to create wrappers for <html></html> , just <script></script> enough. Corrected. We are waiting for expert editing. - oshliaer pm
  • @AlexanderIvanov, the code for the question is not exactly accepted. Usually, if some stylistic remarks of them are left in the comments or added in response, Duck Learns to Take Cover sep
  • @ Duck, how many users read beyond the first answer? Offer to create another misconception out of the blue? And so the topic is dead. Let the order be and beauty. In any case, it dawned on me, I will consider, thanks for the comment. - oshliaer September
  • @AlexanderIvanov, well, you can correct the first answer, since it’s your benefit =) It’s not usual to edit the question itself, to bring the author’s code in its original form, just in case - Duck Learns to Hide
  • @AlexanderIvanov, the code in question makes sense to edit only in order to bring it to the form convenient for perception by other users. That is, correct the formatting of the text of the code, no more . Otherwise, it may happen that, as a result of the edits, the essence of the question will no longer be understood. - Streletz

1 answer 1

Conceptually, you came up very correctly. I think this is a good code.

But in practice, it is not clear what tryExchange returns?

 function tryExchange() { //void var userInterface = HtmlService.createTemplateFromFile('Index.html') .evaluate(); SpreadsheetApp.getUi().showModelessDialog(userInterface, 'Estimate'); } 

Bonus HtmlService. How to transfer data to the client?

  • As I understand it, tryExchange simply creates a template from Index.html, i.e. runs the program. Then it calls Main.js, which in turn calls Client.js. Client.js via google.script.run should call the server function putValuesRange, which will return the value on GoogleSheet. - Andrey Kuravlev
  • Thus, your code should not return anything ( void ), but should transfer to Ui a set of HtmlOutput . - oshliaer
  • @AndreyKuravlev, what would the achivka, or something wrong with the decision? - oshliaer
  • What achivku? I recently on the resource. - Andrey Kuravlev