UiApp已弃用。请改用HtmlService

Egz*_*ifi 5 google-sheets google-apps-script

我在Google电子表格中使用了一个Google脚本从中导出一些数据。他们最近更新了电子表格,但出现此错误:

UiApp已弃用。请改用HtmlService

var app = UiApp.createApplication().setTitle('Export');
Run Code Online (Sandbox Code Playgroud)

有谁遇到这个问题,有解决办法吗?

谢谢

Rub*_*bén 1

请首先学习使用“vanilla”HTML/JavaScript/CSS 开发 Web 应用程序的基本知识。Mozilla 开发者网络和 freecodecamp.com 以及其他许多网站可能会有所帮助。

了解开发 Web 应用程序的基本知识后,请阅读HTML 服务:创建和提供 HTML。下面是一个非常简单的 Web 应用程序代码,包括 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');
}
Run Code Online (Sandbox Code Playgroud)

下面是上面的代码,适用于在 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)
}

Run Code Online (Sandbox Code Playgroud)

如果您没有时间或意愿学习,请考虑使用无代码工具。由于您已经在使用 Google Sheets,因此如果您的电子表格已经有数据表(工作表的第一行有列标题,每个列标题下方都有值),那么 Google AppSheet 可能是一个不错的起点。要从 Google Sheets 创建无代码应用程序,请单击扩展 - AppSheet。

资源

有关的