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

Delete record from google sheet using mit app inventor

We come with third project in series that is delete record from google sheet using mit app inventor. So We forward our third 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 “. Second post was ” Read data from google sheet using MIT APP INVENTOR “. In future we will more projects in this series.

Project Description :

This project is basicaly extension work of our last project. So making a project delete record 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 select 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. Now select the data you want to delete. Press Delete button. Your data will be deleted permanently from google sheets.

MIT APP INVENTOR

Finally, we come with mit app inventor. We build that project very simple with two 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. Now we select the data we want to delete. Press the delete button. then data will delete from google sheet. In bellow you can see the simple looks of our app.

Delete record 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. Fourthly, 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 INVENTORFinally, when we press delete button then it set new web1 url with field selection index and delete function. And call the web1 to perform the task.

Delete record 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 Delete 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);
  }
    
   //DELETE SINGLE RECORD
   else if (e.parameter.func == "Delete") {
    var record = e.parameter.id;
    var ss = SpreadsheetApp.getActive();
    var sh = ss.getSheets()[0];
    sh.deleteRow(parseInt(record) + 1);  
    return ContentService.createTextOutput("Success");  
 } 
  
}

……………….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