如何将二维数组显示为 html table 用于 Google Web 应用程序页面(使用 GAS)

How to display a 2-D array as an html table for a Google Web App Page (using GAS)

使用 code.gs 文件,我从 Google 电子表格中检索数据并将其放入二维数组中,然后对数组进行一些操作(使用转置、冷凝等)。

我正在尝试了解如何创建一个网络应用程序/网页,将此二维数组显示为 html table(前提是还能够设置 table 规格,如宽度、颜色等)。

有没有人知道如何做到这一点?

一般来说,这将告诉您如何操作。只是为了显示 HTML.

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

要选择特定数据,您需要使用 .gs 文件来获取价差 sheet,就像您已经完成的那样。现在,当您完成对数组的修改后,将其存储在 Properties Service 或 Cache Service 中。

在您的 HTML 页面中,编写一个回调 .gs 文件的 JS 函数。

google.script.run
  .withSuccessHandeler( function(array) { ... //We'll get to this in a moment... }) 
.getMyArray();

在您的 .gs 文件中,编写一个函数 'getMyArray'。让它从 属性 或缓存服务中检索数组并使其成为 return 数组。

现在,它是 Success Handeler,使用您的数组,并将其设为 table。

        // 'array' here will be the return of .getMyArray()
  .withSuccessHandler( function(array) {
    for (var i in array) {
      // Here, make every object into a string of the table you want
      // i.e. "<table><td>" + array[i] + "<td> ..."
      // Insert that string into some div.innerHTML
     }
.getMyArray();

像圆周率一样简单