I was getting problemas with my code to format the borders of a table in a Google Document and
Tanaike helpe me here
The problem now is that my table is not getting formatted, it is as if the code doesn`t find the table. It remains with the default borders. Could you help me?
function susbstituirTabela (docID, arrayTabela, texttofind){
const doc = DocumentApp.openById(docID);
var body = doc.getBody();
var rgel = body.findText(texttofind);
var element = rgel.getElement();
var childIndex = body.getChildIndex(element.getParent());
var arrayFinal = [];
for (let i = 0; i < arrayTabela.length; i++) {
let t = [];
if (i == 0) {
t.push('Vencimento');
t.push('N.');
t.push('Valor');
t.push('Saldo')
} else {
if (arrayTabela[i].vencimento != "") {
t.push(arrayTabela[i].vencimento.split(',')[0]);
}
t.push(arrayTabela[i].nparcela);
t.push(arrayTabela[i].parcela.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }));
t.push(arrayTabela[i].saldo.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }));
arrayFinal.push(t);
}}
// var t = [
// ['Vencimento', 'N. Parcela', 'Valor'],
// ['Row 2, Cell 1', 'Row 2, Cell 2']
// ];
body.getChild(childIndex).asText().setText('');
var tab = body.insertTable(childIndex,arrayFinal);
tab.setColumnWidth(0, 60);
tab.setColumnWidth(1, 30);
tab.setColumnWidth(2, 80);
tab.setColumnWidth(3, 100);
var table = body.getTables()[0];
doc.saveAndClose();
var index = Docs.Documents.get(docID).body.content[body.getChildIndex(table) + 1].startIndex;
var requests = [{ updateTableCellStyle: { tableCellStyle: { borderRight: { dashStyle: "SOLID", width: { magnitude: 0, unit: "PT" }, color: { color: { rgbColor: { red: 0 } } } }, borderLeft: { dashStyle: "SOLID", width: { magnitude: 0, unit: "PT" }, color: { color: { rgbColor: { red: 0 } } } } }, tableStartLocation: { index }, fields: "borderRight,borderLeft" } }];
Docs.Documents.batchUpdate({ requests }, docID);
}
2
Answers
Thanks all for your help. Got it working like this:
You need to change your request.
Try the following: