0

I have a SpreadSheet on Google Drive and I'm updating the content using PHP API (https://developers.google.com/sheets/api/guides/values).

I store here reports from my projects. Each project has its sheet.

When the project has no sheet (new project), I create a new sheet for this project called by the name of a new project.

The sheets is created as a last one.

This is my current code to create a new Sheet:

$body = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(
  ['requests' => ['addSheet' => ['properties' => ['title' => $project_name]]]]
);

$result = $service->spreadsheets->batchUpdate($spreadsheetId, $body);

I would like to have sheets sorted alphabetically. Excluding the first sheet, where are some global statistics.

Is there any way to change the order of the sheets using Google SpreadSheet API?

2 Answers 2

1

This would be the workflow:

Sign up to request clarification or add additional context in comments.

Comments

0

I just found the solution ;-)

$requests = [
    new Google_Service_Sheets_Request([
        'updateSheetProperties' => [
            'fields' => 'index',
            'properties' => [
                'sheetId' => $sheet_id,
                'index' => $i,
            ],
        ],
    ])
];
$batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
    'requests' => $requests
]);
$result = $service->spreadsheets->batchUpdate($spreadsheetId, $batchUpdateRequest);

1 Comment

Yes, that's it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.