Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

clear validated cells using a batch update using pygsheets

I have a pygsheets work sheet with cells that have been filled in and would like to clear the cells after pulling the data into python.

My issue is that I have validated the cells with a particular data format then when I try to batch update the sheet the cells are either not going empty (if I use None for the batch update) or an error occurs when I use "".

Please can you help me update the cells to be empty. I have read the documentation and haven’t come across how this is done. I have seen a values_batch_clear method but it seems to be on the spreadsheet.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import pygsheets

spread_sheet_id = "...insert...spreadsheet...id"
spreadsheet_name = "...spreadsheet_name..."
wks_name_or_pos = "...worksheet_name..."

spreadsheet = pygsheets.Spreadsheet(client=service,id=spread_sheet_id)
wksheet = spreadsheet.worksheet('title',wks_name_or_pos)


# trying to batch update cells (that have a data validation format) to make them empty again
wksheet.update_values_batch('C2:F6', 
    [[None, None, None, ""], 
     [None, None, None, ""], 
     [None, None, None, ""], 
     [None, None, None, ""], 
     [None, None, None, ""]])

>Solution :

pygsheets.Worksheet.clear() should work:

import pygsheets

spread_sheet_id = "...insert...spreadsheet...id"
spreadsheet_name = "...spreadsheet_name..."
wks_name_or_pos = "...worksheet_name..."

spreadsheet = pygsheets.Spreadsheet(client=service,id=spread_sheet_id)
wksheet = spreadsheet.worksheet('title',wks_name_or_pos)

wksheet.clear(start='C2', end='F6')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading