google sheets horizontal alignment

≯℡__Kan透↙ 提交于 2021-01-28 10:41:42

问题


I'm trying to change a cell format to horizontal alignment for the text. Can't get it to work. Here is my code so far.

data={
  "requests":[
  {
    "horizontalAlignment": {
        'range': {
            "sheetId": sheetId,
            "startRowIndex": 0,
            "endRowIndex": 10,
            "startColumnIndex": 0,
            "endColumnIndex": 1
        },
        'Center'
    }
  }

  ]
}


result = g.service.spreadsheets().batchUpdate(spreadsheetId=key, body=data).execute()

not sure how to specify the range in there with the horizontal alignment.


回答1:


How about this modification?

Modified script :

data={
  "requests": 
  [
    {
      "updateCells": 
      {
        "rows": 
        [
          {
            "values": 
            [
              {
                "userEnteredFormat": 
                {
                  "horizontalAlignment": "CENTER"
                }
              }
            ]
          }
        ],
        "range": 
        {
          "sheetId": sheetId,
          "startRowIndex": 0,
          "endRowIndex": 10,
          "startColumnIndex": 0,
          "endColumnIndex": 1
        },
        "fields": "userEnteredFormat"
      }
    }
  ]
}

result = g.service.spreadsheets().batchUpdate(spreadsheetId=key, body=data).execute()

Reference :

  • REST Resource: spreadsheets

If I misunderstand your question, please tell me. I would like to modify my answer.




回答2:


Use repeatCell to update at once.

{
  repeatCell: {
    cell: {
      userEnteredFormat: {
        horizontalAlignment: "CENTER",
        verticalAlignment: "MIDDLE",
      }
    },
    range: {
      sheetId: 0,
      startRowIndex: 0,
      endRowIndex: 10,
      startColumnIndex: 0,
      endColumnIndex: 1,
    },
    fields: "userEnteredFormat"
  }
}


来源:https://stackoverflow.com/questions/50874219/google-sheets-horizontal-alignment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!