i not able find way horizontally align table in google doc using google apps script. have thoroughly checked of documentation, , 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 attribute "table properties" menu option.
any thoughts on how align table using google apps script?
i though setting attributes complete table, getting content of each cell , add attribute.
in following code tables in document, go each cell , apply formatting. know shouldn't couldn't find easier way it.
hope helps.
function myfunction() { var doc = documentapp.getactivedocument(); var style = {}; style[documentapp.attribute.horizontal_alignment] = documentapp.horizontalalignment.right; var body = doc.getbody(); for(var = 0 ; < body.getnumchildren(); i++) { if(body.getchild(i).gettype() == 'table') { var table = body.getchild(i).astable(); var rows = table.getnumrows(); var cols = table.getchild(0).astablerow().getnumchildren(); for(var j =0 ; j< rows; j++) { for(var k =0; k<cols; k++) { body.getchild(i).astable().getcell(j,k).getchild(0).setattributes(style); } } } } }
Comments
Post a Comment