Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 在google sheets中创建CEP的源代码_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 在google sheets中创建CEP的源代码

Google apps script 在google sheets中创建CEP的源代码,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我需要在谷歌电子表格中创建一个表单,允许我编写CEP(巴西邮政编码),并自动完成地址、城市、社区、州和一个名为IBGE的代码。我正在尝试使用应用程序脚本来完成它,但没有结果。 我使用了本页()的源代码作为指南,并开发了以下脚本。 *为了安全起见,我删除了SpreeadsheetID function myCEP() { var spsID = 'deletedforsecurityreasons'; var sheetN = 'RCA' var sps = SpreadsheetAp

我需要在谷歌电子表格中创建一个表单,允许我编写CEP(巴西邮政编码),并自动完成地址、城市、社区、州和一个名为IBGE的代码。我正在尝试使用应用程序脚本来完成它,但没有结果。 我使用了本页()的源代码作为指南,并开发了以下脚本。 *为了安全起见,我删除了SpreeadsheetID

function myCEP() {
  var spsID = 'deletedforsecurityreasons';
  var sheetN = 'RCA'
  var sps = SpreadsheetApp.openById(spsID);
  var sheet = sps.getSheetByName(sheetN);
  var firstR = 18;
  var lastR = 23;
  var data = sps.getDataRange().getValues();

  for(i in data){
    var row = data[i];
    var cep = sheet.getRange("Z19").getValue();
    var rua = sheet.getRange("I20").getValue();
    var bairro = sheet.getRange("Y21").getValue();
    var cidade = sheet.getRange("H22").getValue();
    var uf = sheet.getRange("X22").getValue();
    var ibge = sheet.getRange("E24").getValue();
    var startRow = 1 + +i;
  }
  function meu_callback(conteudo) {
        if (!("erro" in conteudo)) {
            //Atualiza os campos com os valores.
            sheet.getElementById('rua').setValue=(conteudo.logradouro);
            sheet.getElementById('bairro').set.Value=(conteudo.bairro);
            sheet.getElementById('cidade').set.Value=(conteudo.localidade);
            sheet.getElementById('uf').set.Value=(conteudo.uf);
            sheet.getElementById('ibge').set.Value=(conteudo.ibge);
        } //end if.
        else {
            //CEP não Encontrado.
            sheet.getElementById('rua').value=("CEP não encontrado.");
        }
    }
  function pesquisacep(valor) {
    //Nova variável "cep" somente com dígitos.
    var cep = valor.replace(/\D/g, '');
    //Verifica se campo cep possui valor informado.
    if (cep != "") {
      //Expressão regular para validar o CEP.
      var validacep = /^[0-9]{8}$/;
      //Valida o formato do CEP.
      if(validacep.test(cep)) {
        //Cria um elemento javascript.
        var script = document.createElement('script');
        script.src = 'https://viacep.com.br/ws/'+ cep + '/json/?callback=meu_callback';
        document.body.appendChild(script);
            } //end if.
       else {
                //cep é inválido.
                sheet.getElementById('rua').value=("Formato de CEP inválido.");
        }
    };

  }
  SpreadsheetApp.flush();
}

我不知道GoogleSheets是否允许我解决这个问题,也不知道问题是否出在源代码语法上。我的表单中没有得到任何结果。

我将这样开始函数:

function myCEP() {
  var sps = SpreadsheetApp.openById('ID');
  var sheet = sps.getSheetByName('RCA');
  var rg=sheet.getRange(18,1,6,sheet.getLastColumn());
  var data = rg.getValues();

不幸的是,我无法继续,因为根本不清楚在那之后你想做什么。

欢迎。请描述你的代码应该做什么,你在哪里卡住了。可能。但您的代码可能无法出售。请实践一下,我想做的是,当我写CEP时,例如:18053380,在单元格(“Z19”)中,我自动在另一个单元格(“I20”)中键入街道名称,在单元格(“Y21”)中键入邻里的名称,在单元格(“H22”)中键入城市名称,在单元格(“X22”)中键入州名称,最后在单元格(“E24”)中键入IBGE代码。所有这些信息都将从页面中提取(“cep+”/json/?Callback=meu_Callback”)是否可以这样做?