Google 文档 API:如何更新 table 的对齐方式?

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

我在 google 文档中有一个 Table 并且想将其对齐方式更改为 -0.71 但我没有看到任何 Python API更改 table 属性。使用 google UI 上的 UI 可以轻松完成此操作(如下所示):

我也尝试查看以下 requests 但找不到:

updateTableColumnProperties
updateTableCellStyle

为了进行调试,我创建了一个包含上述对齐方式的文档,并尝试转储其中的 JSON。但是我在 JSON.

中没有看到 alignment 关键字

目前无法这样做。您可以通过单击问题编号旁边的星号为 Apps 脚本创建一个 Feature Request for the Docs API, and you can also subscribe to this one,以便为请求提供更高的优先级并接收更新。

如果要执行第二个请求,您可以使用 Clasp.

从命令行调用脚本

感谢@jescanellas 的回复。

我发现了一个 hack,这可能不是最好的解决方案,但很有效。

1) 更新段落样式,根据需要设置缩进、对齐方式。这里的 start_idx 是需要创建 table 的索引。

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) 创建table,它将在新的缩进位置创建。

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