更改Google文档中表格的列宽

时间:2015-06-05 13:35:24

标签: google-apps-script multiple-columns google-docs

有人知道这里有什么问题吗?我有另一个代码,具有这个确切的代码并且有效!

 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);

错误消息是:

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

PS:该表通常出现在Document

1 个答案:

答案 0 :(得分:2)

确定。只需将表格变为var tabela = [];

即可

您已经将数组推入另一个数组,这使得它成为2D。 忘记索引1.它似乎确实是零。

相关问题