Search code examples
google-docs-apigoogle-api-python-client

Google Docs API : How to update alignment of the table?


I have a Table in the google docs and want to change its alignment to -0.71 but i do not see any Python API to change table properties. This can be done easily using following UI on google UI (as shown below):

I also tries looking at following requests but could not find it:

updateTableColumnProperties
updateTableCellStyle

For debugging, i created a doc with mentioned alignment and tried dumping JSON of it. But i do not see alignment keyword in the JSON.

enter image description here


Solution

  • Thanks @jescanellas for reply.

    I found a hack, this may not be the best solution but works.

    1) Update paragraph style and set the indentation, alignment as required. Here the start_idx is the index where table needs to be created.

    request = [{
         'updateParagraphStyle': {
             'paragraphStyle': {
                 'namedStyleType': 'HEADING_5',
                 'direction': 'LEFT_TO_RIGHT',
                 'alignment': 'START',
                 'indentFirstLine': {
                     'magnitude': -51.839999999999996,
                     'unit': 'PT'
                 },
                 'indentStart': {
                     'magnitude': -51.839999999999996,
                     'unit': 'PT'
                 },
             },
             'fields': '*',
             'range': {
                   'startIndex': start_idx,
                   'endIndex':  end_idx
             }
         }
     }]
    
    

    2) Create the table, it will get created at new indented place.

    request = [{
           'insertTable': {
               'rows': 1,
               'columns': 1,
               'location': {
                 'segmentId':'',
                 'index': start_idx
               }
           },
       }]