Google 工作表 "repeatCell" 从现有单元格中删除格式

Google Sheets "repeatCell" strips formatting from existing cells

我正在尝试在 Google sheet 秒内复制一些简单的击键。我想将整个 sheet 更改为字体 Balthazar 和大小 11。我可以通过 ctrl + a 并在下拉列表中选择字体和大小来做到这一点。但是,我想做到 1000 sheets.

我的问题是,当我使用以下代码执行此操作时,它会删除单元格中的现有格式。我该如何避免这种情况?

这是我的代码:

 align=None
 fontFamily='balthazar'
 fontSize = 11
 data={
          "requests": 
          [
            {
              "repeatCell": 
              {
                "cell": 
                {
                    "userEnteredFormat": 
                        { "horizontalAlignment": align ,   #'CENTER','LEFT','RIGHT',
                          "textFormat":  { 
                            "fontFamily": fontFamily,
                            "fontSize":  fontSize
                          }
                      }
                },
                "range": 
                {
                  "sheetId": sheetId,
                  "startRowIndex": startRowIndex,
                  "endRowIndex": endRowIndex,
                  "startColumnIndex": startColumnIndex,
                  "endColumnIndex": endColumnIndex
                },
                "fields": "userEnteredFormat"
              }
            }
          ]
        }

您想添加新格式(例如 horizo​​ntalAlignment 和 textFormat),而所有单元格的原始格式 NOT 已修改。即,当 "A1" 具有红色背景色时,即使请求正文添加了新格式,您也不想更改背景色。如果我的理解是正确的,这个修改怎么样?

发件人:

"fields": "userEnteredFormat"

收件人:

"fields": "userEnteredFormat/textFormat,userEnteredFormat/horizontalAlignment"

本次修改只能修改horizontalAlignmenttextFormat

如果我误解了你的问题,我很抱歉。

编辑:

我了解到您只想更改字体系列和字体大小。你能试试这个领域吗?请仅修改请求正文的字段。

"fields": "userEnteredFormat/textFormat/fontFamily,userEnteredFormat/textFormat/fontSize"

已添加:

The document of Sheets API says that fields is "string (FieldMask格式)”。所以上面的值也可以写成如下形式。

"fields": "userEnteredFormat.textFormat.fontFamily,userEnteredFormat.textFormat.fontSize"