从 google 网络应用中的 getValues 函数生成 html table
Generate html table from getValues function in google web app
现在我的工作功能是从 google 电子表格 table 中获取值,并在 google 网络应用程序中 return 它。但它没有 table 视图。我如何将其表示为 html table?
code.gs
//generate web-app
function doGet() {
return HtmlService.createHtmlOutputFromFile('index');
}
function returnCellValue(range1) {
return SpreadsheetApp.openById('1d_qxlDQm3aAfN9zIszqmCmILCK9cVT7PpzchMHliSjM').getSheetByName('output').getRange(range1).getValues();
}
function test1() {
var ss = SpreadsheetApp.openById('1d_qxlDQm3aAfN9zIszqmCmILCK9cVT7PpzchMHliSjM').getSheetByName('output');
returnCellValue('A2:E10');
}
//get data from form
function emailTech(form){
var ss = SpreadsheetApp.openById('1d_qxlDQm3aAfN9zIszqmCmILCK9cVT7PpzchMHliSjM').getSheetByName('output');
var nameBox = form.techEmail;
ss.getRange("A1").setValue(nameBox);
}
index.html
<script type="text/javascript">
function onSuccess(B2Value) {
document.getElementById('output').innerHTML = B2Value;
}
google.script.run.withSuccessHandler(onSuccess).returnCellValue('A2:E10');
function formSubmit() {
google.script.run.emailTech(document.forms[0]);
}
</script>
<div id="output">1</div>
<form>
<input type="text" value=" " name="techEmail" />
<input type="button" onClick="formSubmit(); google.script.run.test1(); google.script.run.withSuccessHandler(onSuccess).returnCellValue('A2:E10'); google.script.run.emailTech(document.forms[0])" value="Show" />
</form>
一切正常,我像网络应用程序一样发布它,并在 sheet 'data' 上的 table 中输入文本框编号(1024、9710、00/ 等) ,然后这个数字在 sheet 'output' 上的 A1 中设置,然后从这个 sheet 我将数据拉到网络应用程序,但它看起来像简单的文本,而不是 table。如何在 table 视图中显示它?
link 在网络应用上 https://script.google.com/macros/s/AKfycbwYkJfplYLVEaXy9FVV5b6BrXkZ6bPmF5ZHrlzrpuQ/dev
您没有将数据转换为 HTML table。
尝试将 B2Value
转换为 html table,然后再将其写入输出元素。
这是一个原始函数:
function toHTMLTable(a) {
var content = a.map(function(row, i) {
var rowHTML = row.map(function (col) {
return "<td>" + col + "</td>";
}).join("");
return "<tr>" + rowHTML + "</tr>";
}).join("");
return "<table>" + content + "</table>";
}
现在我的工作功能是从 google 电子表格 table 中获取值,并在 google 网络应用程序中 return 它。但它没有 table 视图。我如何将其表示为 html table?
code.gs
//generate web-app
function doGet() {
return HtmlService.createHtmlOutputFromFile('index');
}
function returnCellValue(range1) {
return SpreadsheetApp.openById('1d_qxlDQm3aAfN9zIszqmCmILCK9cVT7PpzchMHliSjM').getSheetByName('output').getRange(range1).getValues();
}
function test1() {
var ss = SpreadsheetApp.openById('1d_qxlDQm3aAfN9zIszqmCmILCK9cVT7PpzchMHliSjM').getSheetByName('output');
returnCellValue('A2:E10');
}
//get data from form
function emailTech(form){
var ss = SpreadsheetApp.openById('1d_qxlDQm3aAfN9zIszqmCmILCK9cVT7PpzchMHliSjM').getSheetByName('output');
var nameBox = form.techEmail;
ss.getRange("A1").setValue(nameBox);
}
index.html
<script type="text/javascript">
function onSuccess(B2Value) {
document.getElementById('output').innerHTML = B2Value;
}
google.script.run.withSuccessHandler(onSuccess).returnCellValue('A2:E10');
function formSubmit() {
google.script.run.emailTech(document.forms[0]);
}
</script>
<div id="output">1</div>
<form>
<input type="text" value=" " name="techEmail" />
<input type="button" onClick="formSubmit(); google.script.run.test1(); google.script.run.withSuccessHandler(onSuccess).returnCellValue('A2:E10'); google.script.run.emailTech(document.forms[0])" value="Show" />
</form>
一切正常,我像网络应用程序一样发布它,并在 sheet 'data' 上的 table 中输入文本框编号(1024、9710、00/ 等) ,然后这个数字在 sheet 'output' 上的 A1 中设置,然后从这个 sheet 我将数据拉到网络应用程序,但它看起来像简单的文本,而不是 table。如何在 table 视图中显示它?
link 在网络应用上 https://script.google.com/macros/s/AKfycbwYkJfplYLVEaXy9FVV5b6BrXkZ6bPmF5ZHrlzrpuQ/dev
您没有将数据转换为 HTML table。
尝试将 B2Value
转换为 html table,然后再将其写入输出元素。
这是一个原始函数:
function toHTMLTable(a) {
var content = a.map(function(row, i) {
var rowHTML = row.map(function (col) {
return "<td>" + col + "</td>";
}).join("");
return "<tr>" + rowHTML + "</tr>";
}).join("");
return "<table>" + content + "</table>";
}