I am not able to find a way to horizontally align a table in a Google Doc using Google Apps Script. I have thoroughly checked all of the documentation, and also blindly tried several approaches.
Attempt One:
var cells = [
['Company', rowData[3]],
['Title', rowData[4]],
];
var tableStyle = {};
tableStyle[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT;
var mentorTable = body.appendTable(cells);
var myTable = body.appendTable(cells);
myTable.setAttributes(tableStyle);
Attempt Two:
var cells = [
['Company', rowData[3]],
['Title', rowData[4]],
];
var mentorTable = body.appendTable(cells);
myTable.setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
The Google Docs UI supports changing this attribute from the "Table Properties" menu option.
Any thoughts on how to align a table using Google Apps Script?
I realize this question is relatively old, but I found the following worked for me. Rather than setting the alignment directly on the cell, I need to set it the child.
// create table
table = body.appendTable();
// add row
var tr = table.appendTableRow();
// add cell and right align
var td = tr.appendTableCell('hello world!');
td.getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With