Google Sheets API - Formatting inserted values
<p>Through this code I've update a bunch of rows in Google Spreadsheet.
The request goes well and returns me the <code>updatedRange</code> below.</p>

<pre><code>result = service.spreadsheets().values().append(
    spreadsheetId=spreadsheetId,
    range=rangeName,
    valueInputOption="RAW",
    insertDataOption="INSERT_ROWS",
    body=body
).execute()
print(result)
print("Range updated")
updateRange = result['updates']['updatedRange']
</code></pre>

<p>Now I would like to do a <code>batchUpdate</code> request to set the formatting or set a protected range, but those API require a range specified as <code>startRowIndex</code>, <code>endRowIndex</code> and so on.</p>

<p>How could I retrieve the rows index from the <code>updatedRange</code>?</p>

<p>Waiting for a native or better answer, I'll post a function I've created to translate a <code>namedRange</code> into a <code>gridRange</code>.
The function is far from perfect and does not translate the sheet name to a sheet id (I left that task to another specific function), but accept named ranges in the form:</p>

<ul>
<li><code>sheet!A:B</code></li>
<li><code>sheet!A1:B</code></li>
<li><code>sheet!A:B5</code></li>
<li><code>sheet!A1:B5</code></li>
</ul>

<p>Here is the code</p>

<pre><code>    import re

    def namedRange2Grid(self, rangeName):
        ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        match = re.match(".*?\!([A-Z0-9]+)\:([A-Z0-9]+)", rangeName)
        if match:
            start = match.group(1)
            end = match.group(2)
            matchStart = re.match("([A-Z]{1,})([1-9]+){0,}", start)
            matchEnd = re.match("([A-Z]{1,})([1-9]+){0,}", end)
            if matchStart and matchEnd:
                GridRange = {}
                letterStart = matchStart.group(1)
                letterEnd = matchEnd.group(1)
                if matchStart.group(2):
                    numberStart = int(matchStart.group(2))
                    GridRange['startRowIndex'] = numberStart - 1
                if matchEnd.group(2):
                    numberEnd = int(matchEnd.group(2))
                    GridRange['endRowIndex'] = numberEnd

                i = 0
                for l in range(0, len(letterStart)):
                    i = i + (l * len(ascii_uppercase))
                    i = i + ascii_uppercase.index(letterStart[l])
                GridRange['startColumnIndex'] = i

                i = 0
                for l in range(0, len(letterEnd)):
                    i = i + (l * len(ascii_uppercase))
                    i = i + ascii_uppercase.index(letterEnd[l])
                GridRange['endColumnIndex'] = i + 1

                return GridRange
</code></pre>

python google-spreadsheet-api