javascript - 如何使用电子表格中的值创建下拉菜单?
问题描述
我正在尝试创建一个下拉菜单,其中的值位于电子表格的特定列中。
我尝试用 foo 制作单元格,但我不知道如何将它们调用到我的 html 文件中。这有效率吗?或者你能告诉我另一种方式来调用它们到我的 html 文件。
尝试了此代码,但不知道如何将其返回到 html。
function email_dropdown(divname)
{
var open_sheet = SpreadsheetApp.openByUrl(')getSheetByName');
SpreadsheetApp.setActiveSpreadsheet(open_sheet);
var active_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('*********');
active_sheet.activate();
var dropdown = "<select id = 'email_dropdown'> Email";
var row_val = active_sheet.getRange("**").getValues();
var row_length = row_val.length;
var row_data = active_sheet.getRange("**");
for (var row = 2; row <= row_length; row++)
{
dropdown = dropdown + row_data.getCell(**).getValue();
}
dropdown = dropdown + "</select>"
Logger.log(dropdown);
}
解决方案
酷,你已经解决了大部分问题:) 现在你需要做类似下面的事情,因为你有数组中的值
function yourTestfunction() {
var exampleValues = ['one', 'two', 'three'];
// after your values have been stored in the array
var sheetValuesEl = document.querySelector("#js_sheetValues");
// populate select with values
for(var i = 0; i < exampleValues.length; i++) {
// Create the option
var optionValue = document.createElement("option");
// Set the option text
optionValue.textContent = exampleValues[i];
// Add the option to the select drop down
sheetValuesEl.appendChild(optionValue);
}
}
yourTestfunction()
<select id="js_sheetValues"></select>
推荐阅读
- excel - 将单元格复制并粘贴到过滤器框vba中
- postgresql - PGError:错误:运算符不存在:数字=布尔
- amazon-web-services - 删除 aws neptune 中的所有数据
- c# - RT Linux 中的 C# 硬实时线程?
- c# - Json用2个数组反序列化字符串
- opengl - GLSL 复杂错误:从 vec4 隐式转换为 vec3
- wpf - 如何绑定 WPF 窗口宽度和高度但仍正确使用 WindowStarupLocation?
- mysql - 查询:计算一个表中的参数在另一个表中不存在的次数
- python - 创建一个新变量,它是python中另一个变量的每周最小值/最大值
- javascript - 如何检测应该更新先前对象的属性?