Alcyone
Alcyone

Reputation: 15

Google Sheets API PHP - Append new rows with border of rows and height of row

How to add new rows to my sheets, with style like border and height of rows?

this my code:

    $body = new Google_Service_Sheets_ValueRange([
        'values' => $this->values
    ]);

    $params = [
        'valueInputOption' => 'USER_ENTERED',
        // 'insertDataOption' => "INSERT_ROWS"
    ];

    $insert = [
        'insertDataOption' => "INSERT_ROWS"
    ];
    $result = $this->service->spreadsheets_values->append(
        $this->spreadID,
        $this->sheet,
        $body,
        $params,
        $insert
    );

or is there any method to accomplish this?

Upvotes: 1

Views: 1196

Answers (1)

Dangetsu Kami-sama
Dangetsu Kami-sama

Reputation: 101

You must use batchUpdate method for update sheet styles. https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate https://developers.google.com/sheets/api/samples/formatting

My example for change background color:

$this->_service()->spreadsheets->batchUpdate($this->_spreadsheetId, new \Google_Service_Sheets_BatchUpdateSpreadsheetRequest( [
    'requests' => [
        new \Google_Service_Sheets_Request([
            'repeatCell' => [
                'range'          => [
                    'sheetId' => $this->_sheetId,
                    'startRowIndex' => $newRowIndex,
                    'endRowIndex' => $footerIndex,
                    'startColumnIndex' => 0,
                    'endColumnIndex' => 7
                ],
                "cell"  => [
                    "userEnteredFormat" => [
                        "backgroundColor" => $backgroundColor
                    ]
                ],
                "fields" => "UserEnteredFormat(backgroundColor)"
            ]
        ]),
    ]
]));

Upvotes: 2

Related Questions