在使用Html服务的网站中显示电子表格数据 [英] Display Spreadsheet data in Sites with Html Service
问题描述
我显示
我想要做什么类似于教程,而不是使用UI服务来显示表格,我想使用HTML服务。来自此问题的人提到您可以使用模板化HTML以HTML格式显示Spreadsheet数据。有谁能详细阐述这个话题吗?像这一个简单的例子将非常有用因为我希望看到它的演示可行。
谢谢!
有一个简单的示例,使用模板化的HTML来显示文档中可用的电子表格数据中的表格 here 。 我已经发布正在运行的副本,利用Waqar教程中的相同数据进行简单比较。原文电子表格就在这里。 (编辑:脚本也提供在下面。)
Code.gs
//此脚本中的所有代码都从
复制// https://developers.google.com/apps-script/guides/html-service-templates
函数doGet(){
return HtmlService
.createTemplateFromFile('index')
.evaluate();
$ b $ function getData(){
return SpreadsheetApp
.openById('0AvF9FEyqXFxAdEplRHp5dGc4Q1E3OXMyV2s4RktiQWc')
.getDataRange()
.getValues( );
}
index.html
< pre class =lang-html prettyprint-override>
<? 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>
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!
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>
这篇关于在使用Html服务的网站中显示电子表格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!