Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UiApp has been deprecated. Please use HtmlService instead

I have a google script that I'm using in google spreadsheet to export some data from there. Recently they update the spreadsheet and I'm getting this error:

UiApp has been deprecated. Please use HtmlService instead

var app = UiApp.createApplication().setTitle('Export');

Does anyone had this problem, any solution?

Thank you

like image 445
EgzonArifi Avatar asked Feb 09 '19 09:02

EgzonArifi


2 Answers

Starting point:

function openDialog() {
  var html = HtmlService.createHtmlOutputFromFile('export');
  SpreadsheetApp.getUi()
      .setWidth(640)
      .setHeight(400)
      .showModalDialog(html, 'Export');
}

Docs: https://developers.google.com/apps-script/guides/html/

like image 65
tokland Avatar answered Sep 19 '22 14:09

tokland


Please start by learning the pretty basics of developing a web application using "vanilla" HTML/JavaScript/CSS. Mozilla Developers Network and freecodecamp.com among many others might be helpful.

Once you know the pretty basics of developing a web application, read HTML Service: Create and Serve HTML. Below is a very simple code for a web app including HTML/JavaScript/CSS.

function doGet(e){
  const css = '<style> p { color: blue;} </style>';
  const html = '<p>Hello world!</p>';
  const js = '<script>document.addEventListener("click",() => alert("Clicked!"))</script>';
  return HtmlService.createHtmlOutput(css + html + js)
  .setTitle('My first web app')
  .addMetaTag('viewport', 'width=device-width, initial-scale=1');
}

Below is the above code adapted to be used to show a simple modal dialog in Google Sheets

function showDialog(e){
  const css = '<style> p { color: blue;} </style>';
  const html = '<p>Hello world!</p>';
  const js = '<script>document.addEventListener("click",() => alert("Clicked!"))</script>';
  SpreadsheetApp.getUi().showModalDialog(
    HtmlService.createHtmlOutput(css + html + js), 
    'My first modal dialog'
  )
  .setWidth(300)
  .setHeight(100)
}

If you don't have time or will to learn, consider to use a no-code tool. As you are already using Google Sheets, Google AppSheet might be a good place to start specially if your spreadsheet already has data tables (sheet having column headers on the first row, values below each of them). To create a no-code app from Google Sheets, click on Extensions - AppSheet.

Resources

  • https://developers.google.com/apps-script/guides/dialogs#custom_dialogs
  • https://developers.google.com/apps-script/guides/web

Related

  • Uploading file to spreadsheet shows "UiApp has been deprecated. Please use HtmlServices instead"
like image 1
Rubén Avatar answered Oct 24 '22 00:10

Rubén