Create table from sheet data
In this example, I have created a flextable, whose cells are populated by the data from a Spreadsheet.
References:
Example Demo:
Example Code:
function doGet(){
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var flexTable = app.createFlexTable().setStyleAttribute('border', '1px solid black')
.setStyleAttribute('borderCollapse','collapse')
.setBorderWidth(1);
//Get Data from spreadsheet
var spreadsheetId = 't2Hx-ohk6E_DhtexDElvySA';//Change it to your Spreadsheet ID
var dataArray = getData(spreadsheetId);
//Load data into table cells
for (var row = 0; row<dataArray.length; row++){
for (var col = 0; col<dataArray[row].length; col++){
flexTable.setText(row, col, dataArray[row][col].toString());
}
}
panel.add(flexTable);
app.add(panel);
return app;
}
function getData(spreadsheetId){
var ss = SpreadsheetApp.openById(spreadsheetId);
var sheet = ss.getSheets()[0].getDataRange();
return sheet.getValues();
}