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
  New on python. Needs help with Google sheet jeromep 1 134 Yesterday, 06:47 PM
Last Post: deanhystad
Sad Selenium update broke python code genericusername12414 1 249 Mar-16-2024, 07:33 PM
Last Post: snippsat
  Python and pandas: Aggregate lines form Excel sheet Glyxbringer 12 1,893 Oct-31-2023, 10:21 AM
Last Post: Pedroski55
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 3 758 Aug-09-2023, 05:51 PM
Last Post: Calab
  [notice] A new release of pip available: 22.3.1 -> 23.1.2 [notice] To update, run: C: GoldenHarvey 3 5,300 Jun-06-2023, 05:43 PM
Last Post: GoldenHarvey
  Error 1064 (42000) when executing UPDATE SQL gratiszzzz 7 1,487 May-22-2023, 02:38 PM
Last Post: buran
  class Update input (Gpio pin raspberry pi) caslor 2 799 Jan-30-2023, 08:05 PM
Last Post: caslor
  How to read csv file update matplotlib column chart regularly SamLiu 2 1,072 Jan-21-2023, 11:33 PM
Last Post: SamLiu
  cannot update PIP tester_V 1 726 Jan-12-2023, 07:17 AM
Last Post: tester_V
  Priority Queue with update functionality PythonNewbee 4 1,951 Dec-29-2022, 12:13 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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