0% encontró este documento útil (0 votos)
182 vistas5 páginas

Gestión de Datos con Google Sheets

El código define funciones para manejar datos de personas en una hoja de cálculo de Google. Permite guardar, buscar y editar nombres, apellidos, sexo, dirección y celular de individuos. Usa Google Apps Script para interactuar con la hoja de cálculo como base de datos y manejar eventos del formulario en la página web.

Cargado por

DocEst
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
182 vistas5 páginas

Gestión de Datos con Google Sheets

El código define funciones para manejar datos de personas en una hoja de cálculo de Google. Permite guardar, buscar y editar nombres, apellidos, sexo, dirección y celular de individuos. Usa Google Apps Script para interactuar con la hoja de cálculo como base de datos y manejar eventos del formulario en la página web.

Cargado por

DocEst
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd

CODIGO DE INDEX.

HTML

<script src=”//code.jquery.com/jquery-1.10.2.js”></script>
<link rel= “stylesheet” href= https://ssl.gstatic.com/docs/script/css/add-ons.css”>
<script>
Function procesaFormulario (){
Google.script.run.procesaFormDatosPersona(document.forms[0]:
}
Function buscaInformacion (){
google.script.run.withSuccessHandler(getNombres).getNombresSS(document.forms[0]);
google.script.run.withSuccessHandler(getApellidos).getApellidosSS(document.forms[0]);
google.script.run.withSuccessHandler(getSexo).getSexoSS(document.forms[0]);
google.script.run.withSuccessHandler(getDireccion).getDireccionSS(document.forms[0]);
google.script.run.withSuccessHandler(getCelular).getCelularSS(document.forms[0]);
}
Function editaInformacion (){
google.script.run.setNombresSS(document.forms[0]);
google.script.run.setApellidosSS(document.forms[0]);
google.script.run.setSexoSS(document.forms[0]);
google.script.run.setDireccionSS(document.forms[0]);
google.script.run.setCelularSS(document.forms[0]);
}
function getNombres(nombres){
var =document.getElementById(‘nombres’);
txtNombres.value=nombres;
}
function getApellidos(apellidos){
$(“#apellidos”).val(apellidos);
}
function getSexo(sexo){
$(“#sexo”).val(sexo).change();
}
function getDireccion(direccion){
$(“#direccion”).val(direccion);
}
function getCelular(celular){
$(“#celular”).val(celular);
}
$(function(){
$(“#guardar”).click(procesaFormulario);
$(“#buscar”).click(buscaInformacion);
$(“#editar”).click(editaInformacion);
});

</script>

<html>
<? var
hojaCalculo=SpreadsheetApp.openById( “https://docs.google.com/spreadsheets/d/1vew9EOnb2vmaf2JYLItNn98r4I
EK3dd9MLS0v9j-XvU/edit#gid=0”);
var hojaParametros=hojaCalculo.getSheetByName(‘Parametros’);
var ultimaFila=hojaParametros.getLastRow();
¿>

<div>
<form id= “datospersona” name= “datosPersona”>
<br>
Nombre (s):
<br><input type= “text” id= “nombre” name= “nombre” placeholder= “Primer y/o Segundo nombre” required>

<br>
Apellido (s):
<br><input type= “text” id= “apellido” name= “apellido” placeholder= “Primer y/o Segundo apellido” required>
<br>
ID:
<br><input type= “text” id= “id” name= “id” placeholder= “Numeros y Letras” required>
<br>
Sexo:
<br>
<select id= “sexo” name= “sexo” required>
<? i=2;
while (i<=ultimaFila){

?> <option value="<?=hojaParametros.getRange(i, 1).getValue()?>"><?=hojaParametros.getRange(i, 1).getValue()?


></option>
<?
i++;
}

?>

</select>

<br>
Direccion:
<br><input type= “text” id= “direccion” name= “direccion” placeholder= “Direccion Residencia” required>

<br>
Celular:
<br><input type= “text” id= “celular” name= “celular” placeholder= “Numero de movil” required>

<br><br>

<button class= “action” id= “guardar”>Guardar </button>


<button id= “buscar”>Buscar </button>
<button id= “editar”>Editar </button>

</form>
</div>
</html>
CODIGO DE MAIN.GS

//**********************Función llama a el HTML ****************


Function doGet() {
Logger.leg( Utilities.jsonStringify(e) );

If (le.parameter.page) {
//Cuando no se especifica una página, retorna “Página de inicio”
return HtmlService.createTemplateFromFile( “Index”).evaluate();
}

//sino, usa los parámetros recogidos desde el script en un archivo HTML

Var template = HtmlService.createTemplateFormFile(e.parameter.page)


Template.action=ScriptApp.getService().getUrl();
return template.evaluate();
}

//***************Función que busca en la Sheet (Como BD) y retorna valor fila *******************

function buscaReturnRow(sId) {
var hojaCalculo =
SpreatsheetApp.openById( “https://docs.google.com/spreadsheets/d/1vew9EOnb2vmaf2JYLItNn98r4IEK3dd9MLS0
v9j-XvU/edit#gid=0”)
var hojaDatos = hojaCalculo.getSheetByName( “Datos”);

var numColumns = hojaDatos.getLastColumn();


var ultimaFila = hoja Datos.getLastRow();
var sw=0;
v row = hojaDatos.getRange(1,1,ultimaFila,numColumns).getValues();
for (var i=1; i<row.length; i++) {
for (var col=0; col<row(i).length; col++) {
var id=row(i)(2).toString();
If (sId ++ id){
var indice = i+1;
sw=1;
}
}
}
If (sw++ 1){
}
}

//******Función que busca en la Sheet (Como BD) y retorna la información en una fila y columna específica******

function buscaEnSheet(sId, columna){

var hojaCalculo =
SpreatsheetApp.openById( “https://docs.google.com/spreadsheets/d/1vew9EOnb2vmaf2JYLItNn98r4IEK3dd9MLS0
v9j-XvU/edit#gid=0”)
var hojaDatos = hojaCalculo.getSheetByName( “Datos”);

var numColumns = hojaDatos.getLastColumn();


var ultimaFila = hoja Datos.getLastRow();
var sw=0;
var row = hojaDatos.getRange(1,1,ultimaFila,numColumns).getValues();
for (var i=1; i<row.length; i++) {
for (var col=0; col<row(i).length; col++) {
var id=row(i)(2).toString();
If (sId ++ id){
Var índice = i+1;
sw=1;
}
}
}
If (sw++ 1){
var info=hojaDatos.getRange(indice, columna).getValue();
return info;
}
}

//*****Función que guarda los datos en la Sheet***********


function procesaFormDatosPersona(e){

var sNombre=e.nombre;
var sApellido=e.apellido;
var sId=e.id;
var sSexo=e.sexo;
var sDireccion=e.direccion;
var sCelular=e.celular;

var hojaCalculo =
SpreatsheetApp.openById( “https://docs.google.com/spreadsheets/d/1vew9EOnb2vmaf2JYLItNn98r4IEK3dd9MLS0
v9j-XvU/edit#gid=0”)
var hojaDatos = hojaCalculo.getSheetByName( “Datos”);
var ultimaFila=hojaDatos.getLastRow;

hojaDatos.getRange(ultimaFila+1,1).setValue(sNombre);
hojaDatos.getRange(ultimaFila+1,2).setValue(sApellido);
hojaDatos.getRange(ultimaFila+1,3).setValue(sId);
hojaDatos.getRange(ultimaFila+1,4).setValue(sSexo);
hojaDatos.getRange(ultimaFila+1,5).setValue(sDireccion);
hojaDatos.getRange(ultimaFila+1,6).setValue(sCelular);

//*********Función que devuelve los nombres (Fila numero 1)*****


function getNombresSS(e){
Var sId=e.id;
Return buscaEnSheet(sId,1);
}

//*********Función que devuelve los apellidos (Fila numero 2)*****


function getApellidosSS(e){
Var sId=e.id;
Return buscaEnSheet(sId,2);
}

//*********Función que devuelve el sexo (Fila numero 4)*****


function getSexoSS(e){
Var sId=e.id;
Return buscaEnSheet(sId,4);
}

//*********Función que devuelve la Direccion (Fila numero 5)*****


function getDireccionSS(e){
Var sId=e.id;
Return buscaEnSheet(sId,5);
}

//*********Función que devuelve el Celular (Fila numero 6)*****


function getCelularSS(e){
Var sId=e.id;
Return buscaEnSheet(sId,6);
}

//****Función de cambia el nombre de la persona***


function setNombresSS(e){
var sId=e.id;
var sNombre=e.nombre;
var row=buscaReturnRow(sId);
var hojaCalculo =
SpreatsheetApp.openById( “https://docs.google.com/spreadsheets/d/1vew9EOnb2vmaf2JYLItNn98r4IEK3dd9MLS0
v9j-XvU/edit#gid=0”)
var hojaDatos = hojaCalculo.getSheetByName( “Datos”);
hojaDatos.getRange(row,1).setValue(sNombre);

También podría gustarte