Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Gspread insert new columns at location?

I am trying to use Gspread to insert new columns at a location. I found add_cols methods, but it inserts only in the last column of spreadsheet.

There are other methods such as: insert_rows, resize or append_rows but nothing can solve my problem. Did i miss anything? Thank you

like image 896
Khanh Le Avatar asked Oct 29 '22 09:10

Khanh Le


1 Answers

Use the default batch update API for this

spreadsheetId=''
sheetId=''

sht = gc.open_by_key(spreadsheetId)

requests = []

requests.append({
      "insertDimension": {
        "range": {
          "sheetId": sheetId,
          "dimension": "COLUMNS",
          "startIndex": 2,
          "endIndex": 4
        },
        "inheritFromBefore": True
      }
    })

body = {
    'requests': requests
}

sht.batch_update(body)
  • Googgle Sheets API v4. Insert an empty row or column
  • gspread. Lower-level method that directly calls spreadsheets.batchUpdate
like image 191
contributorpw Avatar answered Nov 12 '22 23:11

contributorpw