Rcoster
Rcoster

Reputation: 3210

Change column width of a table in a Google Doc

Someone knows what is wrong here? I have another code that has this exact code and works!

 var dados = sheet.getRange('B10:D19');
  var tabela = [[]];
  tabela.push(['Quem', 'Quanto', 'Onde']);
  tabela.push([dados.getCell(1, 1).getValue(), formatThousands(dados.getCell(1, 2).getValue()), dados.getCell(1, 3).getValue()]);
  tabela.push([dados.getCell(2, 1).getValue(), formatThousands(dados.getCell(2, 2).getValue()), dados.getCell(2, 3).getValue()]);
  tabela.push([dados.getCell(3, 1).getValue(), formatThousands(dados.getCell(3, 2).getValue()), dados.getCell(3, 3).getValue()]);
  tabela.push([dados.getCell(4, 1).getValue(), formatThousands(dados.getCell(4, 2).getValue()), dados.getCell(4, 3).getValue()]);
  tabela.push([dados.getCell(5, 1).getValue(), formatThousands(dados.getCell(5, 2).getValue()), dados.getCell(5, 3).getValue()]);
  tabela.push([dados.getCell(6, 1).getValue(), formatThousands(dados.getCell(6, 2).getValue()), dados.getCell(6, 3).getValue()]);
  tabela.push([dados.getCell(7, 1).getValue(), formatThousands(dados.getCell(7, 2).getValue()), dados.getCell(7, 3).getValue()]);
  tabela.push([dados.getCell(8, 1).getValue(), formatThousands(dados.getCell(8, 2).getValue()), dados.getCell(8, 3).getValue()]);
  tabela.push([dados.getCell(9, 1).getValue(), formatThousands(dados.getCell(9, 2).getValue()), dados.getCell(9, 3).getValue()]);
  tabela.push([dados.getCell(10, 1).getValue(), formatThousands(dados.getCell(10, 2).getValue()), dados.getCell(10, 3).getValue()]);

  body.appendParagraph('Últimos gastos:');
  var tabelaDoc = body.appendTable(tabela);
  tabelaDoc.setColumnWidth(0, 50);
  tabelaDoc.setColumnWidth(1, 80);

The error message is:

Child index (0) must be less than the number of child elements (0).Dismiss

PS: The table appears normally on Document

Upvotes: 0

Views: 2233

Answers (1)

Daniel Möller
Daniel Möller

Reputation: 86600

Ok. Simply change your table var to var tabela = [];

You are already pushing an array into another, that makes it 2D. Forget about the index 1. It seems it's zero based indeed.

Upvotes: 2

Related Questions