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
  Can't update new python version on Pycharm GOKUUUU 6 419 Jul-23-2022, 09:24 PM
Last Post: GOKUUUU
  pymysql; insert on duplicate key update fails wardancer84 4 244 Jun-28-2022, 08:14 PM
Last Post: Larz60+
  Update old Python version because of security threads SanderV 2 418 Jun-06-2022, 07:49 PM
Last Post: SanderV
  python update binary object (override delivered Object properties) pierre38 4 493 May-19-2022, 07:52 AM
Last Post: pierre38
  Is it possible to update a CSS file from Python bigAL_python 4 636 Apr-20-2022, 01:38 PM
Last Post: bigAL_python
  Openpyxl-change value of cells in column based on value that currently occupies cells phillipaj1391 5 850 Mar-30-2022, 11:05 PM
Last Post: Pedroski55
  Matplotlib - automatic update frohr 1 405 Mar-29-2022, 07:05 PM
Last Post: deanhystad
  String concatenation in SQL update statement hammer 3 582 Feb-24-2022, 08:00 PM
Last Post: hammer
  Update plot frohr 3 685 Jan-27-2022, 07:31 PM
Last Post: deanhystad
  Deploy Python to Cloud and save output to Google Drive chandrabr80 2 563 Jan-25-2022, 06:56 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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