如何在弹性表格的每一行的一个单元格中添加复选框、列表框或单选按钮。我正在使用应用程序脚本。我尝试了以下操作,但它仅在最后一行的一个单元格中显示列表框:
function doGet(){
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var listBox = app.createListBox();
listBox.addItem("Yes").addItem("No").setName("myListBox");
var table = app.createFlexTable().setId("myTable");
table.setBorderWidth(1)
table.setCellPadding(1);
//Get Data from spreadsheet
var doc = SpreadsheetApp.openById('Spreadsheet ID');
var spreadsheetId = 'Spreadsheet ID';
var dataArray = getData(spreadsheetId);
for (var row = 0; row<dataArray.length; row++){
for (var col = 0; col<dataArray[row].length; col++){
if( col == 1){
table.setWidget(row, col, listBox);
}
table.setText(row, col, dataArray[row][col].toString());
}
}
app.add(table);
return app;
}
function getData(spreadsheetId){
var ss = SpreadsheetApp.openById(spreadsheetId);
var sheet = ss.getSheets()[0].getDataRange();
return sheet.getValues();
}