Code Monkey home page Code Monkey logo

googlescrips's Introduction

GoogleScrips

Projetos desenvolvidos com GoogleScripts

Web Apps

Exemplo de URL: https://script.google.com/.../exec?username=jsmith&age=21

function doGet(e){
  
  var Form = HtmlService.createTemplateFromFile("form.html")
    
  Form.title = "Titulo";
  return  Form.evaluate().setTitle("Titulo").addMetaTag('viewport', 'width=device-width, initial-scale=1')

}

More...

onEdit

const onEvents = {
    ...
}

function onEdit(event){  

  var ss = SpreadsheetApp.getActive();
    
  try 
  {    
    let sheetName = event.source.getSheetName()
    onEvents[sheetName](event)     
  } 
  catch(error) 
  {
    Logger.log(`Evento não encontrado: ${error} `)
  }
}

More...

doPost

function doPost(e) {
  let body = JSON.parse(
    decodeURI(e.postData.getDataAsString())
  )

  save(e.postData)

  return createTextOutput({body:values, status: status})
    .setMimeType(ContentService.MimeType.JSON);
}

More...

CRUD

Crud GoogleSheet

class Sheets {
    constructor(TabName, ssID) {
        if(ssID) {
            var ssID="<ID>"
            this.sheet = SpreadsheetApp.openById(ssID)
            this.table = this.sheet.getSheetByName(TabName)
        } else {
            this.sheet = SpreadsheetApp.getActiveSpreadsheet()
            this.table = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(TabName)
        }    
    }
    
    /**
     * Salva informações de um array
     * @param {array} data ["item1", "item2", ...]
     */
    save(data) { 
        try {
            
            let line
            try{
                line = parseInt(data[0])
                data[0] = '=ROW()'
            } catch(e){
                Logger.log("Erro ao converter linha: "+data[0])
            }      
            
            const atualizarLinha = _ => {
                this.table.getRange(line,1,1,data.length).setValues([data])
                return true
            }
            
            const adicionarLinha = _ => {
                this.table.appendRow( data )      
                return true
            }
            
            line > 0 && atualizarLinha() || adicionarLinha()
            
        } catch(e){ 
            Logger.log('Erro ao salvar: '+e);
            return false;
        }
        return true;
    }
    ...
    
}

More...

googlescrips's People

Contributors

marcoantonioq avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.