Display Spreadsheet data in Sites with Html Service [closed]

穿精又带淫゛_ 提交于 2019-12-11 06:19:44

问题


I displaying What I want to do with similar to this tutorial but instead of using UI Services to display the table, I would like to use HTML Services. Someone from this question mentioned that you could use Templated HTML to display Spreadsheet data in html. Could anyone elaborated on this topic? A simple example like this would very helpful because I'd like to see a demonstration on it works.

Thank you!


回答1:


There is a simple example of using templated HTML to display a table from spreadsheet data available in the documentation, here.

I've published a running copy, utilizing the same data from Waqar's tutorial, for an easy comparison. The source spreadsheet is here, as is the script. (Edit: script is also provided below.)

Code.gs

// All code in this script is copied from
// https://developers.google.com/apps-script/guides/html-service-templates

function doGet() {
  return HtmlService
      .createTemplateFromFile('index')
      .evaluate();
}

function getData() {
  return SpreadsheetApp
      .openById('0AvF9FEyqXFxAdEplRHp5dGc4Q1E3OXMyV2s4RktiQWc')
      .getDataRange()
      .getValues();
}

index.html

<? var data = getData(); ?>
<table border='1px solid black'>
  <? for (var i = 0; i < data.length; i++) { ?>
    <tr>
      <? for (var j = 0; j < data[i].length; j++) { ?>
        <td><?= data[i][j] ?></td>
      <? } ?>
    </tr>
  <? } ?>
</table>


来源:https://stackoverflow.com/questions/16660906/display-spreadsheet-data-in-sites-with-html-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!