Sequential updates to ranges in Google Sheets API via pygsheets - google-sheets

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"

OK, upon reading the source code of the pygsheets library I think I know why this happens. The apply_format method sends a repeatCell request, which basically copies all of the provided cell's properties and applies them to the all of the cells in provided range. So when I provide a cell (the BOLD/L_GREEN_BG objects, which are just a dummy cell objects with only one property defined) with only bold font style, all of the cells in range get all of it's properties, along with default values. Every other subsequent call works similarly.

Related

Copying Conditional Formatting without adding to the data set

I have an inventory and ordering management Sheet where I use color coding via Sheets Conditional Formatting to make some cells quickly visible as having outstanding orders. In my particular case, I am using conditional formatting based on a neighboring cell.
The sheet I built utilizes several columns for ordering cycles with our suppliers. When I am ready to move on to the next ordering cycle, I copy and paste a set of columns to create the new cycle.
The problem that I encounter is this: the new column's Conditional Formatting gets added to the old, both in terms of adding a new column to format, but also referencing the cell from which the copied columns use to decide whether to format.
Original Order Block
In this second image, I have pasted a new order block from Columns AD-AL to Columns AM -AU.
Pasted Order Block
There are two things that I am trying to solve:
I would expect the custom formula to update to =$AR5<>"", but it holds on to the Original Order Block's formula, thus applying the formatting from cells that are in the Original Order Block.
I would expect the range to update to only the new range of AQ5:AQ397, rather than add the additional range to the original order block range.
Each order block needs the conditional formatting to be independent from the one which it was copied.
Thanks in advance.
In this case, you can just remove the "$" from your custom formula and it will move just fine
Your ranges are going to be together as you shown, but will look at the cell at its right

Google Sheets Conditional Formatting based on the cell directly NEXT to, across the entire row

I am looking to show color changes based on decreasing values. I want to add conditional formatting to a row (row 9) based on the cell directly prior (B9<C9 I want to be green, C9>D9 I want to be red). I want an entire row to be conditionally formatted to show growth/decline based on the cell directly before. Is this possible? How can I do so? enter image description hereI have the formulas I want to use, but I don't know how to accurate apply them to the entire Row 9 (as of now I'm manually inputting the 3 custom conditions on each cell)
You can use the following Custom Formulas from Range C9:9. Feel free to interchange the background color that will fit your needs.
For Green (Increasing), =C9>OFFSET(C9,0,-1)
For Red (Decreasing), =C9<OFFSET(C9,0,-1)
For Yellow (Same), =C9=OFFSET(C9,0,-1)
OFFSET() lets you shift the rows/columns based on a reference cell.
In this custom formulas, I get the previous cell value referenced to the current cell by setting the offset_columns to -1.
Sample:
Output:

Conditional formatting messes up when FILTER results change

So I have a sheet that outputs varying results from a FILTER function, depending on how you set some checkboxes.
One of the results columns has a conditional formatting rule that changes the colour of just that column depending upon the contents of the cell. It's a really simple one that says, if TEXT CONTAINS Matt, then make the cell blue.
But sometimes, and only sometimes, when the checkboxes are changed, so the results list becomes shorter, some of the conditional formatting colours stay in the lower cells even though the cell no longer contains any text at all.
Has anyone seen this before, or knows a solution?

Changing cell colour if value modified in google sheets

I am working in google sheets and want the background colour of the cell to change to red if it's value has been modified. However, I want to avoid using any script for that. Is it possible to do this through conditional formatting?
If not, is there any other way to do it? (again no scripts)
this can't be done without a script because there is no way how to track down a "modified value". conditional formatting can be done based on something eg "something" stands for a fixed point in a timeline from which can change be anchored like today's date, max from range, equal to a value, etc.
Possible with Conditional Formatting provided there is a record somewhere of the cell's initial value (the reference for what constitutes a change). This need not be in the same sheet. Say that reference is a named range Tigger that represents the 'initial' value of say C6 in the sheet with the cell whose colour is to be changed.
Select C6 then Format, Conditional formatting..., Format cells if..., Custom formula is:
=$C$6<>indirect("Tigger")
choose red fill and click Done.
The colour is lost if the cell returns to the initial value (unless the content of the named range is modified to have itself been changed meanwhile).

Conditional Formatting cells in column up to and including the last one with text entered

I am using Google Sheets and trying to write a custom formatting rule that seems like it should be simple. I am trying to figure out how to conditionally format all the cells in a column INCLUDING AND ABOVE (but not below) the cell that meets my condition.
I've found a lot of things that will format the entire column, but that's not what I'm looking for.
The image below is a basic example that I manually colored in to do what I want.
It's for my budget spreadsheet, where each row is an entry from a particular date. I have an "Agreement" column that is empty except when I enter the date that I reconciled the budget. I want it to color that cell and all the empty cells above it green, signifying at a glance: "everything up to this point is ok/has been checked over". Then as time goes by, and I enter another date several rows below, I want it to extend the colored shading up to there.
I've been searching, but it is hard to articulate this; if I say "until this cell" I get results for "shade cell until text is entered"; any mention of "above" and "below" generally relates to the values in the cells; I've found some things about Indirect but just for a single cell above, not for all cells above the current cell.
Wondering if this is even possible...
Google Sheets example
If you create a conditional formatting rule for column A using a Custom Formula you can use this formula:
=COUNTIF(ROW(),"<="&LARGE(ArrayFormula(IF(ISBLANK(A1:A100),"TRUE",ROW(A1:A100))),1))
The larger the ranges you use, the slower it will be however.

Resources