Get sheet value by apps script to html table - CodyLab

Get sheet value by apps script to html table -AppsScriptLab

Get sheet value by apps script to html table 

         Friends, today we all see how to get google spreadsheet cell value by apps script to html tabe.

for this goal we use following codes and follow following steps.

                                                Step-1

first of all see the sheet that used in this program.
This is a Example sheet only. you should use as you need.
 

                                                Step-2
We used following code to read the html file. Name Index.html
function  doGet () {
 var  x ;
     x = HtmlService.createTemplateFromFile('Index').evaluate();
     x.setTitle("Project Title");
    return x;
}

                             Step-3

We used following code to read the html file. Name css.html

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}


                                                     Step-4
We used following code to read the sheet value .


function getDataR(cF) {
  return SpreadsheetApp
      .openById ( '1Jen2OZemz7nr1NRPb4eVOEGN_pLf9WTsnWnBFxtf_gE '// 
      .getSheetByName('Sheet1').getDataRange().getValues();
}



                                                       Step-5
We used following html table and code.

This code to get read value: <? var data = getDataR(); ?>

This code to include css style: <?!= include('css') ?>

We define the row using array [row][column] = [0] First row [0] First column.


<!DOCTYPE html>
<html>
<head>
<? var data = getDataR(); ?>
<?!= include('css') ?>
</head>
<body>

<h2>HTML Table</h2>

<table>
  <tr>
    <th><?= data[0][0] ?></th>
    <th><?= data[0][1] ?></th>
    <th><?= data[0][2] ?></th>
    <th><?= data[0][3] ?></th>
  </tr>
  <tr>
    <td><?= data[1][0]; ?></td>
    <td><?= data[1][1] ?></td>
    <td><?= data[1][2] ?></td>
    <td><?= data[1][3] ?></td>
  </tr>
  <tr>
    <td><?= data[2][0]; ?></td>
    <td><?= data[2][1] ?></td>
    <td><?= data[2][2] ?></td>
    <td><?= data[2][3] ?></td>
  </tr>
 <tr>
    <td><?= data[3][0]; ?></td>
    <td><?= data[3][1] ?></td>
    <td><?= data[3][2] ?></td>
    <td><?= data[3][3] ?></td>
  </tr>
  <tr>
    <td><?= data[4][0]; ?></td>
    <td><?= data[4][1] ?></td>
    <td><?= data[4][2] ?></td>
    <td><?= data[4][3] ?></td>
  </tr>
 <tr>
    <td><?= data[5][0]; ?></td>
    <td><?= data[5][1] ?></td>
    <td><?= data[5][2] ?></td>
    <td><?= data[5][3] ?></td>
  </tr>
  <tr>
    <td><?= data[6][0]; ?></td>
    <td><?= data[6][1] ?></td>
    <td><?= data[6][2] ?></td>
    <td><?= data[6][3] ?></td>
  </tr>
  
  
</table>

</body>
</html>
                            
                                                      Step-6
We used following css. Name: css.html


<style>
table {
  font-family: arialsans-serif;
  border-collapse: collapse;
  width: 100%;
}

tdth {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;
}
</style>

All the above code produce following result:

See live Demo click here Demo Example2.
CodyLab Blogger CodyLab Blogger
                                                                             Have a nice day!
-------------------------- -------------------------
-------------------------- -------------------------

Post a Comment

Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.