arturkuchynski
arturkuchynski

Reputation: 980

GoogleSheets API v4 Python : Unable to re-order sheets in google spreadsheet

I want to reorder a Sheet1 moving it from index 6 to index 0.


def rename_worksheet(spreadsheet_id,
                     sheet_id,
                     new_title,
                     credentials, index=0):
    service = discovery.build('sheets', 'v4', credentials=credentials)

    requests = {
        "updateSheetProperties": {
            "properties": {
                "sheetId": sheet_id,
                "title": new_title,
                "index": index,
            },
            "fields": "title",
        }
    }

    body = {
        'requests': requests
    }

    service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id, body=body).execute()

But the sheet remains on It's old position. enter image description here

Upvotes: 1

Views: 100

Answers (1)

Tanaike
Tanaike

Reputation: 201368

How about this modification?

In your request body, by "fields": "title", only the title is updated. In your case, please add index to fields as follows. By this, the title and index of the sheet are updated.

From:

"fields": "title",

To:

"fields": "title,index",

Upvotes: 1

Related Questions