7

如果我滚动电子表格,行的标题字段被隐藏,我需要在同一个电子表格中使用粗体文本格式。

问题
我可以通过电子表格 api 设置冻结行和样式 - 可以吗?

4

3 回答 3

10

这现在在 v4 API 中可用。

以下是 JAVA API 实现的参考: https ://developers.google.com/resources/api-libraries/documentation/sheets/v4/java/latest/com/google/api/services/sheets/v4/model/ GridProperties.html#setFrozenRowCount(java.lang.Integer)

这是 API 文档: https ://developers.google.com/sheets/reference/rest/v4/spreadsheets#gridproperties

如果您想使用 App 脚本执行此操作,您也可以: https://developers.google.com/apps-script/reference/spreadsheet/sheet#setFrozenRows(Integer)

这是我使用 Ruby API 提出的请求:

update_sheet_properties: {
  properties: {
    sheet_id: 'YOUR SHEET ID HERE',
    grid_properties: { frozen_row_count: 4 }
  },
  fields: 'gridProperties.frozenRowCount'
}
于 2016-08-08T22:18:35.920 回答
3

如果有人在寻找使用 PHP 的解决方案来格式化标题并在滚动时冻结标题,那么您可以使用下面提到的这种方法:

        //$client will be your google service client request after authorization.           
        $service = new Google_Service_Sheets($client);

        $formatRowColrequests = [
            new Google_Service_Sheets_Request([
              "repeatCell" => [
                "range" => [
                  "sheetId" => $setSheetId, //set your sheet ID
                  "startRowIndex" => 0,
                  "endRowIndex" => 1,
                  "startColumnIndex" => 0,
                  "endColumnIndex" => 100
                ],
                "cell" => [
                  "userEnteredFormat" => [
                    "horizontalAlignment" => "CENTER",
                    "textFormat" => [
                      "fontSize" => 9,
                      "bold" => true
                    ]
                  ]
                ],
                "fields" => "userEnteredFormat(textFormat,horizontalAlignment)"
              ]
            ]),
            new Google_Service_Sheets_Request([
                'updateSheetProperties' => [
                    'properties' => [
                        'sheetId' => $setSheetId,
                        'gridProperties' => [
                            'frozenRowCount' => 1
                        ]
                    ],
                    "fields"=> "gridProperties.frozenRowCount"
                ]
            ])
        ];
        $batchUpdateCellFormatRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
            'requests' => $formatRowColrequests
        ]);
        $service->spreadsheets->batchUpdate($spreadsheetId, $batchUpdateCellFormatRequest);
于 2019-01-29T11:47:23.307 回答
1

这是如何在android中做到这一点。花了一段时间才弄清楚。文档给出了几个例子[为此]。

 SpreadsheetProperties properties = new SpreadsheetProperties();
        properties.setTitle(calendar.getTime().toString());

        Spreadsheet requestBody = new Spreadsheet();

        GridProperties gridProperties = new GridProperties();
        gridProperties.setFrozenRowCount(2);

        SheetProperties sheetProperties = new SheetProperties();
        sheetProperties.setTitle("my new sheet");
        sheetProperties.setGridProperties(gridProperties);
        Sheet sheet = new Sheet();
        sheet.setProperties(sheetProperties);
        List<Sheet> sheets = new ArrayList<>();
        sheets.add(sheet);
        requestBody.setSheets(sheets);

        requestBody.setProperties(properties);
于 2019-02-02T22:43:09.610 回答