【问题标题】:repeatcell request not updating cell properties in Google Sheetsrepeatcell 请求未更新 Google 表格中的单元格属性
【发布时间】:2018-09-12 09:26:38
【问题描述】:

我的 Google Sheets PHP API repeatcell 请求未更新单元格属性。

是否有任何可行的替代方法来更新文本粗体、背景颜色等单元格属性?

是否有任何关于 Google 电子表格 PHP API 的适当文档?

我正在使用“google/apiclient”:“^2.0”。

这是我使用的代码和收到的响应:

$sheetId = $service->spreadsheets->get($spreadsheetId, ['ranges' => 'SLA Data!A1']);
    $range = new Google_Service_Sheets_GridRange();
    $range->setSheetId($sheetId->sheets[0]->properties->sheetId);
    $range->setEndRowIndex(2);
    $range->setEndRowIndex(5);
    $range->setStartColumnIndex(0);
    $range->setEndColumnIndex(5);
    $cell = new Google_Service_Sheets_CellData();
    $cellFormat = new Google_Service_Sheets_CellFormat();
    $textFormat = new Google_Service_Sheets_TextFormat();
    $textFormat->setBold(true);
    $cellFormat->setTextFormat($textFormat);
    $cell->setUserEnteredFormat($cellFormat);
    $repeatCell = new Google_Service_Sheets_RepeatCellRequest();
    $repeatCell->setRange($range);
    $repeatCell->setFields('userEnteredFormat.textFormat.bold');
    $requests = new Google_Service_Sheets_Request();
    $requests->setRepeatCell($repeatCell);

    $batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
    $batchUpdateRequest->setRequests($requests);

响应代码:

Google_Service_Sheets_BatchUpdateSpreadsheetResponse Object
(
[collection_key:protected] => replies
[repliesType:protected] => Google_Service_Sheets_Response
[repliesDataType:protected] => array
[spreadsheetId] => 1ZlQPGuI0q0bIDAsbl04BALb8_sqXm02aPY0ZCEyeTHc
[updatedSpreadsheetType:protected] => Google_Service_Sheets_Spreadsheet
[updatedSpreadsheetDataType:protected] => 
[internal_gapi_mappings:protected] => Array
    (
    )

[modelData:protected] => Array
    (
    )

[processed:protected] => Array
    (
    )

[replies] => Array
    (
        [0] => Google_Service_Sheets_Response Object
            (
                [addBandingType:protected] => Google_Service_Sheets_AddBandingResponse
                [addBandingDataType:protected] => 
                [addChartType:protected] => Google_Service_Sheets_AddChartResponse
                [addChartDataType:protected] => 
                [addDimensionGroupType:protected] => Google_Service_Sheets_AddDimensionGroupResponse
                [addDimensionGroupDataType:protected] => 
                [addFilterViewType:protected] => Google_Service_Sheets_AddFilterViewResponse
                [addFilterViewDataType:protected] => 
                [addNamedRangeType:protected] => Google_Service_Sheets_AddNamedRangeResponse
                [addNamedRangeDataType:protected] => 
                [addProtectedRangeType:protected] => Google_Service_Sheets_AddProtectedRangeResponse
                [addProtectedRangeDataType:protected] => 
                [addSheetType:protected] => Google_Service_Sheets_AddSheetResponse
                [addSheetDataType:protected] => 
                [createDeveloperMetadataType:protected] => Google_Service_Sheets_CreateDeveloperMetadataResponse
                [createDeveloperMetadataDataType:protected] => 
                [deleteConditionalFormatRuleType:protected] => Google_Service_Sheets_DeleteConditionalFormatRuleResponse
                [deleteConditionalFormatRuleDataType:protected] => 
                [deleteDeveloperMetadataType:protected] => Google_Service_Sheets_DeleteDeveloperMetadataResponse
                [deleteDeveloperMetadataDataType:protected] => 
                [deleteDimensionGroupType:protected] => Google_Service_Sheets_DeleteDimensionGroupResponse
                [deleteDimensionGroupDataType:protected] => 
                [duplicateFilterViewType:protected] => Google_Service_Sheets_DuplicateFilterViewResponse
                [duplicateFilterViewDataType:protected] => 
                [duplicateSheetType:protected] => Google_Service_Sheets_DuplicateSheetResponse
                [duplicateSheetDataType:protected] => 
                [findReplaceType:protected] => Google_Service_Sheets_FindReplaceResponse
                [findReplaceDataType:protected] => 
                [updateConditionalFormatRuleType:protected] => Google_Service_Sheets_UpdateConditionalFormatRuleResponse
                [updateConditionalFormatRuleDataType:protected] => 
                [updateDeveloperMetadataType:protected] => Google_Service_Sheets_UpdateDeveloperMetadataResponse
                [updateDeveloperMetadataDataType:protected] => 
                [updateEmbeddedObjectPositionType:protected] => Google_Service_Sheets_UpdateEmbeddedObjectPositionResponse
                [updateEmbeddedObjectPositionDataType:protected] => 
                [internal_gapi_mappings:protected] => Array
                    (
                    )

                [modelData:protected] => Array
                    (
                    )

                [processed:protected] => Array
                    (
                    )

            )

    )

)

【问题讨论】:

    标签: php api google-sheets-api


    【解决方案1】:

    问题是您没有将 cell 设置为 repeatCell 请求。在repeatCell初始化后添加这一行

    $repeatCell->setCell($cell);
    

    现在它将更新工作表

    【讨论】:

      猜你喜欢
      • 2020-10-13
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多