I'm trying to update some cell ranges with defined format, but I'm running into a problem when the ranges overlap. For example, if I have a range of cells A1:C3 and I want to set cells A2:B2 to have a green background color, and then to have them all have bold font style, the result is only the latter - the background color of the previous cells is overwritten by the bold style. If I do it in the reverse order, the cells have green background but no bold font.
I'm using pygsheets library and this is roughly how my calls work:
# wks is a worksheet object from the created spreadsheet
wks.range("A2:B2", "range").apply_format(L_GREEN_BG, fields="userEnteredFormat")
wks.range("A1:C3", "range").apply_format(BOLD, fields="userEnteredFormat")
The BOLD and L_GREEN_BG are cell objects initialized with a dictionary in json-like format specified by Google Sheets API to match these updates.
My question is: is there any way to not overwrite previously made changes? Doing it sequentially like this would be a lot more handy than making more complex updates to singular cells.
if you want other properties to be unchanged, be more specific on the fields. So in your first case set fields='userEnteredFormat\backgroundColor' and in your second request "userEnteredFormat\textFormat"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With