Codigo DB Sheets Google
Codigo DB Sheets Google
Codigo DB Sheets Google
GS
//************************** Función llama a el HTML *************************************************************
function doGet(e) {
Logger.log( Utilities.jsonStringify(e) );
if (!e.parameter.page) {
// Cuando no se especifica una página, retorna "Pagina de inicio"
return HtmlService.createTemplateFromFile('Index').evaluate();
}
// sino, usa los parametros recogidos desde el script en un archivo HTML
var template = HtmlService.createTemplateFromFile(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){
//******* Función que busca en la Sheet (Como BD) y retorna la información en una fila y columna especifica*********
function procesaFormDatosPersona(e){
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( sDirreccion);
hojaDatos.getRange(ultimaFila+1, 6).setValue( sCelular);
function getNombresSS(e){
var sId = e.id;
return buscaEnSheet(sId, 1);
}
function getApellidosSS(e){
var sId = e.id;
return buscaEnSheet(sId, 2);
}
function getDireccionSS(e){
var sId = e.id;
return buscaEnSheet(sId, 5);
}
function getCelularSS(e){
var sId = e.id;
return buscaEnSheet(sId, 6);
}
function setNombresSS(e){
var sId = e.id;
var sNombre = e.nombre;
var row = buscaReturnRow(sId);
var hojaCalculo = SpreadsheetApp.openById("1vew9EOnb2vmaf2JYLItNn98r4IEK3dd9MLS0v9j-XvU");
var hojaDatos = hojaCalculo.getSheetByName('Datos');
hojaDatos.getRange(row, 1).setValue(sNombre);
}
INDEX.HTML
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<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 txtNombres = document.getElementById('nombre');
txtNombres.value = nombres;
}
function getApellidos(apellidos){
$( "#apellido" ).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>
<div>
<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>
Dirección:
<br><input type="text" id="direccion" name="direccion" placeholder="Direccion recidencia" required>
<br>
Celular:
<br><input type="number" id="celular" name="celular" placeholder="Numero del movil">
<br><br>
<button class="action" id="guardar">Guardar</button>
<button id="buscar">Buscar</button>
<button id="editar">Editar</button>
</form>
</div>
</html>