How to insert and center a spreadsheet in Google Docs using Google Script

I am trying to create a table and it ends up being centered in the body of the document Google DocumentApp

using Google Script

.

At the moment I am creating tables using a For Loop and they are created perfectly, they just won't be centered.

I've tried the following:

Attempt 1:

var insertedTable = updateBody.insertTable(numberOfTables, objectivesTables[g]);            
insertedTable.setAlignment(DocumentApp.HorizontalAlignment.CENTER);

      

RESULT: This causes one table aligned LEFT to stop and time out. (I am using a library I created and I am calling this function from another Script so I dont get an error)

Attempt 2:

var style = {};
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.CENTER;

updateBody.insertTable(numberOfTables, objectivesTables[g]).setAttributes(style);

      

RESULT: All tables are created, but they are left aligned.

I've seen this with Text, Paragraphs and Images, but I can't figure out how to do it with a table, so any help would be kindly received.

+3


source to share


1 answer


A nasty solution might be to put a placeholder in the document, center it manually, and then replace it with a table.



0


source







All Articles