![]() ![]() I needed to paste starting at a particular tab and cell, so I took Sam Berlin's suggestion to use a PasteDataRequest. It always starts the paste at A1 of the first worksheet (tab) and deletes all other tabs. I like Burnash's gspread library, but the import_csv function in his answer is limited. the code is tested with python 3.5, but this thread seemed to be most appropriate to submit it to. On a low level gspread does the same and should be as performant. Good thing about directly using batchUpdate is that it uploads thousands of rows in a second. Sheet_id=find_sheet_id_by_name(worksheet_name) With open(path_to_credentials, 'rb') as token:ĪPI = build('sheets', 'v4', credentials=credentials) Request = API.spreadsheets().batchUpdate(spreadsheetId=SPREADSHEET_ID, body=body) "columnIndex": "0", # adapt this if you need different positioning "rowIndex": "0", # adapt this if you need different positioning If sheet = sheet_name:ĭef push_csv_to_gsheet(csv_path, sheet_id): get(spreadsheetId=SPREADSHEET_ID, fields='sheets.properties') \ Path_to_credentials = 'Credentials/token.pickle' SPREADSHEET_ID = '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms' # Get this one from the link in browser Recipe that should work out of the box:įrom googleapiclient.discovery import build.Hopefully by now you have your credentials stored, so let's move to the actual code quickstart.py can easily be adapted into authenticate.py.Big blue button will get you credentials.json with no extra steps.It uses both Sam's and CapoChino's answers plus some of my own research. So, here is a full recipe of uploading CSVs to gSheets. On the other hand, Sam's answer doesn't elaborate on the details of using the API, which might be confusing at times. Libraries do not explain the authentication well, and don't work with google-provided way of handling credentials. I've spent couple of hours trying to make any of the other answers work.
0 Comments
Leave a Reply. |