Python Forum
Python + Google Sheet | Best way to update specific cells in a single Update()?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python + Google Sheet | Best way to update specific cells in a single Update()?
#1
Question 
Hi all,

I am learning how to use Python + Google Sheet API to update GoogleSheet

I read the developers guide on spreadsheets().values().update()
As shown in the image below, I only want to update specific cells, not a range.
How can I update only cells I want?

https://ibb.co/qp8jpq3

ssName = sheet_ELCSV.title + '!'
    cell_range = 'A2,B2,D2,A3,K3'
    
    values = (
        ('Sell','-2.17','27760.0476'),
        ('Fee', '-2.38285229')
    )
    value_range = {
        'majorDimension' : 'ROWS',
        'values': values
    }
    service.spreadsheets().values().update(
        spreadsheetId = ssID,
        valueInputOption = 'USER_ENTERED',
        range = ssName + cell_range,
        body = value_range
    ).execute()
Reply
#2
Good day!

The below codes serve to update one or many cells in Google Sheet.
Between the two codes below, which would be most effective in using the least Write Request?
This is to minimize the Usage Limit for calling Google Sheet API.
I assume that if TH_MatchedRows = 3, then Code 1 will have 3 Requests, while Code 2 will always have 1 request regardless of TH_MatchedRows size.
Correct me if I'm wrong.

for i in TH_MatchedRows:
        sheet_THCSV.update_cell(i,9,OH_CurRow) 
OR

 TempList = []
 for i in TH_MatchedRows:
    TempList.append(OH_CurRow)

ssName = sheet_THCSV.title + '!'
cell_range = 'I' + str(TH_MatchedRows[-1]) + ':I' + str(TH_MatchedRows[0])
values = TempList
value_range = {
    'majorDimension' : 'COLUMNS',
    'values': [values]
}
service.spreadsheets().values().update(
    spreadsheetId = ssID,
    valueInputOption = 'USER_ENTERED',
    range = ssName + cell_range,
    body = value_range
).execute()
Tyvm
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  |SOLVED] Glob JPGs, read EXIF, update file timestamp? Winfried 5 198 Oct-21-2021, 03:29 AM
Last Post: buran
  Get last row of SQL database and update Turtle 5 223 Oct-14-2021, 07:06 PM
Last Post: Turtle
  install apache-airflow[postgres,google] on Python 3.8.12 virtual env ShahajaK 1 169 Oct-07-2021, 03:05 PM
Last Post: Larz60+
  Python “Formula” Package: How do I parse Excel formula with a range of cells? JaneTan 1 528 Jul-12-2021, 11:09 AM
Last Post: jefsummers
  Python script for excel sheet Nabil 5 805 Jun-01-2021, 02:29 PM
Last Post: anuradha
  NotImplementedError: pseudo-class is not implemented - how to Update Python to solve apollo 1 704 May-16-2021, 08:03 AM
Last Post: buran
  UPDATE SQLITE TABLE - Copy a fields content to another field. andrewarles 14 1,183 May-08-2021, 04:58 PM
Last Post: ibreeden
  Eliminating error in Python update-alternatives Led_Zeppelin 2 840 Apr-14-2021, 12:49 PM
Last Post: Led_Zeppelin
  Raspberry pi Sensehat auto update mrbronz61 4 1,063 Apr-10-2021, 09:13 AM
Last Post: mrbronz61
  How can I iterate through all cells in a column (with merge cells) with openpyxl? aquerci 1 2,443 Feb-11-2021, 09:31 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020