Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp

Read data from google sheet using MIT APP INVENTOR

Here we come with a very good and important project that is read data from google sheet using MIT APP INVENTOR. We forward our second steps towards work with google sheets form mit app inventor. In this series my first post was ” Send data to google sheet from mit app inventor “. In future also you will find lots of post regarding work with google sheets.

Now come to the main topic. Making a project read data from google sheet using MIT APP INVENTOR, we need basic concept of android app making. And some little bit knowledge about mit app inventor blocks. To build our project we use

  • MIT APP INVENTOR
  • Google Sheet
  • App Script

In this project you will learn that how we will fetching data form google sheets. For that, we use a simple Read All button in our app. When you press that button, data will imported as CSV. After that separate each of data and display it at app.

MIT APP INVENTOR

For that project we build very simple app with one button and one list viewer. When we press the read all button. It set the web url. And call it as web. When web got test as CSV. Separate it and display at list viewer. In bellow you can see the simple looks of our app.

Read data from google sheet using MIT APP INVENTOR

Now talk about block programming, you can see very simple logic we used. Firstly, when page is initialise. One global variable naming URL is set with app script url. Secondly, when read all button press. It set the app script url to web1 and call it.

Thirdly, we initialise two global variable with empty list. Finally, when web1 got test. It separate the CSV data. And display it to list viewer. In bellow you can see the programming blocks of our project read data from google sheet using MIT APP INVENTOR.

read data from google sheet using MIT APP INVENTOR

 

 Google Sheet :

Now we have to specified the google sheet. From where we want to read the data. Mind that we have to give the permission that any one can view that sheet.  So in my project it look like that.

 

 App Script :

It is the main portion of our project. We have to create read all data script. How we create that every thing shown in the video. Please watch that video. I am sure you will able to do it by own very easily.

Please find the app script at bellow.

……………CODE………………

function doGet(e) {
  return ManageSheet(e);
}
function doPost(e) {
  return ManageSheet(e);
}

function ManageSheet(e) {

  //READ ALL RECORDS
  if ( e.parameter.func == "ReadAll") {
    var ss = SpreadsheetApp.getActive();
    var sh = ss.getSheets()[0]; 
    var rg = sh.getDataRange().getValues(); 
    var outString = '';
      for(var row=0 ; row<rg.length ; ++row){
        outString += rg[row].join(',') + '\n';  
      } 
    return ContentService.createTextOutput(outString).setMimeType(ContentService.MimeType.TEXT);
  }

}

……………….END…………………

 

 

Not Enough, Need More

E-Mail Subscription





E-Mail Subscription





Table of Contents
Subham Dutta

Subham Dutta

Hi myself Subham Dutta, having 15+ years experience in filed of Engineering. I love to teach and try to build foundation of students. Try to make them imagine what they learn.

Need more this type of content in your E-Mail?



NBCAFE