Ir ao conteúdo
  • Cadastre-se
nanquinote

Atribuir valor célula - google script / javascript

Recommended Posts

Boa noite, tenho uma planilha com a coluna B (produtos) e C (preços). Cada produto tem um código e está atrelado a um preço definido. Preciso de um script pra fazer a atribuição desses preços. Este que eu criei lê os valores da coluna B, mas não atribui na C. Abaixo segue código e log. (Como podem ver, o switch tá caindo no default, então acho que é essa minha forma de atribuição que tá errada)

 

function myFunction() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); 
  var sheet = spreadsheet.getActiveSheet();
  var rangeB = sheet.getRange(2,2,515); 
  var valoresB = rangeB.getValues();
  var rangeC = sheet.getRange(2,3,515); 
  var valorC = rangeC.getValues();

  //[r][c]

  for(var i=2; i<valoresB.length; i++){
    
    switch(valoresB[i][2])
    {
      case 1:
      valorC[i][3].setValue(1.500,00);
      break;
      case 2:
      valorC[i][3].setValue(900,00);
      break;
      case 3:
      valorC[i][3].setValue(2.500,00);
      break;
      case 4: 
      valorC[i][3].setValue(50,00);
      break;
      case 5:
      valorC[i][3].setValue(50,00);
      break;
      case 6:
      valorC[i][3].setValue(300,00);
      break;
      case 7:
      valorC[i][3].setValue(25,00);
      break;
      case 8:
      valorC[i][3].setValue(250,00);
      break;
      case 9:
      valorC[i][3].setValue(200,00);
      break;
      case 10:
      valorC[i][3].setValue(100,00);
      break;
      case 11:
      valorC[i][3].setValue(60,00);
      break;
      case 12:
      valorC[i][3].setValue(800,00);
      break;
      case 13:
      valorC[i][3].setValue(10,00);
      break;
      case 14:
      valorC[i][3].setValue(5,00);
      break;
      case 15:
      valorC[i][3].setValue(80,00);
      break;
      case 16:
      valorC[i][3].setValue(75,00);
      break;
      case 17:
      valorC[i][3].setValue(40,00);
      break;
      case 18:
      valorC[i][3].setValue(80,00);
      break;
      case 19:
      valorC[i][3].setValue(65,00);
      break;
      default:
      valorC = "ERRO";
      break;
    } //switch
} //for
Logger.log(valoresB);
Logger.log(valorC);
} //função
Citação

[16-10-21 19:24:25:237 BRST] [[15.0], [6.0], [10.0], [8.0], [17.0], [2.0], [5.0], [13.0], [1.0], [7.0], [9.0], [19.0], [16.0], [3.0], [12.0], [11.0], [4.0], [14.0], [18.0], [2.0], [6.0], [19.0], [14.0], [16.0], [4.0], [15.0], [5.0], [10.0], [18.0], [3.0], [12.0], [9.0], [1.0], [13.0], [8.0], [7.0], [17.0], [11.0], [5.0], [14.0], [18.0], [1.0], [2.0], [11.0], [12.0], [10.0], [4.0], [9.0], [19.0], [6.0], [17.0], [3.0], [7.0], [13.0], [15.0], [8.0], [16.0], [7.0], [14.0], [15.0], [16.0], [12.0], [3.0], [1.0], [8.0], [4.0], [13.0], [6.0], [2.0], [5.0], [9.0], [10.0], [11.0], [19.0], [18.0], [17.0], [8.0], [4.0], [14.0], [2.0], [10.0], [3.0], [1.0], [16.0], [9.0], [12.0], [6.0], [18.0], [13.0], [15.0], [5.0], [19.0], [17.0], [7.0], [11.0], [9.0], [16.0], [11.0], [17.0], [13.0], [4.0], [19.0], [14.0], [8.0], [5.0], [1.0], [12.0], [3.0], [6.0], [10.0], [7.0], [18.0], [2.0], [15.0], [8.0], [15.0], [10.0], [5.0], [13.0], [16.0], [17.0], [4.0], [2.0], [7.0], [1.0], [14.0], [19.0], [12.0], [11.0], [3.0], [18.0], [9.0], [6.0], [6.0], [16.0], [7.0], [2.0], [3.0], [12.0], [1.0], [14.0], [18.0], [8.0], [9.0], [13.0], [19.0], [17.0], [4.0], [11.0], [10.0], [5.0], [15.0], [9.0], [13.0], [8.0], [17.0], [5.0], [2.0], [7.0], [6.0], [10.0], [15.0], [12.0], [11.0], [4.0], [14.0], [16.0], [18.0], [19.0], [1.0], [3.0], [19.0], [6.0], [16.0], [2.0], [13.0], [5.0], [1.0], [4.0], [9.0], [14.0], [10.0], [11.0], [15.0], [3.0], [17.0], [18.0], [7.0], [12.0], [8.0], [6.0], [5.0], [1.0], [4.0], [13.0], [18.0], [15.0], [10.0], [16.0], [17.0], [11.0], [14.0], [12.0], [19.0], [9.0], [2.0], [7.0], [8.0], [3.0], [4.0], [10.0], [2.0], [3.0], [12.0], [18.0], [5.0], [11.0], [16.0], [6.0], [19.0], [9.0], [1.0], [13.0], [8.0], [14.0], [15.0], [7.0], [17.0], [4.0], [9.0], [11.0], [14.0], [5.0], [12.0], [7.0], [2.0], [8.0], [17.0], [3.0], [15.0], [18.0], [10.0], [13.0], [16.0], [1.0], [19.0], [6.0], [15.0], [5.0], [13.0], [4.0], [10.0], [3.0], [6.0], [11.0], [9.0], [2.0], [14.0], [12.0], [17.0], [19.0], [1.0], [18.0], [8.0], [16.0], [7.0], [7.0], [19.0], [1.0], [11.0], [14.0], [4.0], [13.0], [10.0], [18.0], [12.0], [2.0], [9.0], [16.0], [3.0], [6.0], [8.0], [15.0], [17.0], [5.0], [7.0], [19.0], [1.0], [11.0], [14.0], [4.0], [13.0], [10.0], [18.0], [12.0], [2.0], [9.0], [16.0], [3.0], [6.0], [8.0], [15.0], [17.0], [5.0], [7.0], [13.0], [10.0], [11.0], [14.0], [8.0], [12.0], [18.0], [16.0], [15.0], [9.0], [1.0], [6.0], [2.0], [19.0], [4.0], [17.0], [3.0], [5.0], [10.0], [11.0], [2.0], [19.0], [8.0], [4.0], [17.0], [13.0], [1.0], [9.0], [3.0], [15.0], [18.0], [6.0], [14.0], [7.0], [5.0], [16.0], [12.0], [7.0], [1.0], [19.0], [16.0], [2.0], [15.0], [9.0], [8.0], [3.0], [12.0], [11.0], [18.0], [14.0], [17.0], [4.0], [6.0], [10.0], [13.0], [5.0], [12.0], [4.0], [19.0], [5.0], [3.0], [10.0], [18.0], [2.0], [13.0], [6.0], [17.0], [9.0], [1.0], [7.0], [8.0], [11.0], [15.0], [16.0], [14.0], [19.0], [16.0], [11.0], [5.0], [17.0], [8.0], [9.0], [3.0], [6.0], [18.0], [7.0], [10.0], [1.0], [4.0], [14.0], [12.0], [15.0], [2.0], [13.0], [2.0], [13.0], [19.0], [6.0], [15.0], [18.0], [14.0], [11.0], [8.0], [10.0], [3.0], [12.0], [5.0], [4.0], [16.0], [7.0], [17.0], [9.0], [1.0], [9.0], [17.0], [7.0], [4.0], [3.0], [6.0], [18.0], [2.0], [11.0], [13.0], [19.0], [15.0], [1.0], [12.0], [10.0], [16.0], [5.0], [8.0], [14.0], [4.0], [10.0], [2.0], [19.0], [13.0], [9.0], [14.0], [5.0], [12.0], [8.0], [1.0], [3.0], [7.0], [11.0], [6.0], [16.0], [17.0], [18.0], [15.0], [5.0], [3.0], [17.0], [2.0], [14.0], [8.0], [10.0], [9.0], [11.0], [7.0], [15.0], [18.0], [16.0], [6.0], [19.0], [1.0], [12.0], [4.0], [13.0], [3.0], [8.0], [2.0], [14.0], [5.0], [16.0], [12.0], [17.0], [7.0], [18.0], [13.0], [11.0], [19.0], [4.0], [15.0], [6.0], [9.0], [10.0], [1.0], [18.0], [19.0], [4.0], [15.0], [6.0], [13.0], [3.0], [9.0], [17.0], [10.0], [11.0], [12.0], [2.0], [7.0], [8.0], [16.0], [14.0], [5.0], [1.0], [11.0], [5.0]]
[16-10-21 19:24:25:238 BRST] ERRO

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisar ser um membro para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora





Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas publicações sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×