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
  Python “Formula” Package: How do I parse Excel formula with a range of cells? JaneTan 1 185 Jul-12-2021, 11:09 AM
Last Post: jefsummers
  Python script for excel sheet Nabil 5 466 Jun-01-2021, 02:29 PM
Last Post: anuradha
  NotImplementedError: pseudo-class is not implemented - how to Update Python to solve apollo 1 383 May-16-2021, 08:03 AM
Last Post: buran
  UPDATE SQLITE TABLE - Copy a fields content to another field. andrewarles 14 771 May-08-2021, 04:58 PM
Last Post: ibreeden
  Eliminating error in Python update-alternatives Led_Zeppelin 2 582 Apr-14-2021, 12:49 PM
Last Post: Led_Zeppelin
  Raspberry pi Sensehat auto update mrbronz61 4 745 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 1,470 Feb-11-2021, 09:31 PM
Last Post: nilamo
  How to update values in a pyarrow table? xraphael75 1 878 Jan-25-2021, 02:14 PM
Last Post: xraphael75
  Update Date based on Time/String stevezemlicka 1 469 Jan-08-2021, 06:54 PM
Last Post: Gribouillis
  How to Copy Single Value From One Excel Sheet to Another SunWers 4 692 Dec-29-2020, 05:39 PM
Last Post: SunWers

Forum Jump:

User Panel Messages

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