更改 Google 文档中 table 的列宽
Change column width of a table in a Google Doc
有人知道这里出了什么问题吗?我有另一个代码有这个确切的代码并且有效!
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: table 正常出现在 Document
上
好的。只需将 table 变量更改为 var tabela = [];
您已经将一个数组推入另一个数组,这使其成为二维数组。
忘记索引 1。它似乎确实是基于零的。
有人知道这里出了什么问题吗?我有另一个代码有这个确切的代码并且有效!
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: table 正常出现在 Document
上好的。只需将 table 变量更改为 var tabela = [];
您已经将一个数组推入另一个数组,这使其成为二维数组。 忘记索引 1。它似乎确实是基于零的。