How to update a row using the Gspread python module - python-3.x

Hello basicaly i have this data, compose of name, project, reason and timestamps here's below is the structure
['John Doe', 'Hollywood', 'Good-time', '2022-05-17 15:25:45']
and on the documentation, it only shows how to update an individual cell, but i wanted to update entire row. Thanks in advance

You have 2 ways to update the content of you spreadsheet using gspread.
Using update method
It will update the specified range with values you provide.
Example: updating cells A2 to B2
worksheet.update("A2:B2", [[42], [43]])
Using update_cells
You create a list of Cell object with each value for each cell then update the cells
Examples: updating cells A2 to B2
C1 = Cell(2, 1, 42)
C2 = Cell(2, 2, 43)
worksheet.update_cells([C1, C2])

Related

Excel - get range of data between two rows

I have data in following pattern:
I want a formula to get the data between Content Start and Content End. The amount of content between the start and end is not just limited to 4 and can change.
You don't say what you want to do with this result.
I am assuming you can code the column in which your data is located.
The formula below will return those values as an array. e.g. with your data, the formula will return {1;2;3;4}
The values could be numeric or text.
How you want to handle those values is up to you.
=INDEX($A:$A,N(IF(1,ROW(INDEX($A:$A,MATCH("Content Start",$A:$A,0)+1,1):INDEX($A:$A,MATCH("Content End",$A:$A,0)-1,1)))))
EDIT: Here is an example of using that information to create a sparkline. In this example, the formula above has been wrapped in TRANSPOSE and entered as an array formula in C1:I1. The Sparkline has been entered in B1. As with most charts, Excel is ignoring the #N/A errors.
And here is an example where the sparkline is in A1 and the transposed array is somewhere else, not in view, on the worksheet:
With Worksheets("Your Sheet").Range("A:A")
Set c = .Find("Content Start", LookIn:=xlValues)
Set d = .Find("Content End", LookIn:=xlValues)
ActiveSheet.Range(Cells(c.Row + 1, c.Column), Cells(d.Row - 1, c.Column)).Select
End With
Probably multiple ways doing this, but if you prefer to do it without VBA you could use:
Formula used in B1 (allthough a bit lengthy):
{=INDEX($A$1:$A$10,SMALL((ROW($A$1:$A$10)>MATCH("Content Start",$A$1:$A$10,0))*(ROW($A$1:$A$10)<MATCH("Content End",$A$1:$A$10,0))*ROW($A$1:$A$10),SUM((ROW($A$1:$A$10)>MATCH("Content Start",$A$1:$A$10,0))*(ROW($A$1:$A$10)<MATCH("Content End",$A$1:$A$10,0)))+ROW(A3)))}
Notice it's an array formula entered through CtrlShiftEnter
Drag down....

Creating a cell that updates to new value

I am wondering if there is any way to create a cell that automatically updates to the next in a series in Excel.
If Column 2 contains any of these:
2A
2B
2C
Then the cell would say use 2D next. And then when that column shows 2D, then use 2E, and so on. I have tried using an if function, but I can't seem to get it to work. I plan on having the list of available entries on a separate worksheet that the data will draw from.
Thank you in advanced!
You could try this:
Have the text "2A" in cell A1.
In cell A2, paste this formula:
= LEFT(A$1,LEN(A$1)-1)&CHAR(CODE(RIGHT(A$1,1))+ROWS(A$1:A2)-1)
And drag down as necessary.
EDIT
Based on your comment, you can modify cell A2 to this:
= IF(RIGHT(A1,1)="Z",(LEFT(A1,LEN(A1)-1)+1)&"A",
LEFT(A1,LEN(A1)-1)&CHAR(CODE(RIGHT(A1,1))+1)

Batch cells update with pygsheets

How can I update spreadsheet range with a list of values?
For example if I have range A1:C7 and I want 1, 2, 3, 4, ... 21 values in cells.
I can't even get a cell list with sheet.range function.
cell_list = sh.range('A1:C7', returnas='cells')
cause it does not return cell object if spreadsheet has empty cells.
To update a range of cells you can use a 2d list
wks.update_cells('A2:C7',[[1,2,3],[4,5,6],[7,8,9] ... etc ])
to get cell objects even if you have empty cells, use
get_values('A1', 'C7', returnas='cells', include_all=True)
sheet.range currently dosen't return the exact rectangle specified (sticking to the api v4). Try raising an issue in github to get it fixed.

excel reference to another work book multiple sheets

I am trying to use a formula that would let me copy and paste it down so I dont have to link every-time
The source workbook has tabs named 1,2,3,4,5.....100
I want to use simple formula ='[test.xlsx]1'!$O$117
but I want to replace ='[test.xlsx]**A1**'!$O$117
so it is dynamic and I can copy it down
='[test.xlsx]B1'!$O$117; where B1 = 2
='[test.xlsx]C1'!$O$117; where C1 = 3
I tried ='[SCD PCAP 2Q15 - waterfall.xlsx]&1&'!$O$117
any ideas?
You can do so by Two step process.
Step 1 (Thanks to #Excel Hero for this answer)
1
Open the Name Manager. Control-F3 from the worksheet, and then click the New button.
2
For the Name field in the dialog, enter EVALXFD. I just picked this name it is using column XFD in it. But you can pick whatever name you like.
3
For the Refers to field, enter this
=EVALUATE($XFD1)
4
Click OK and then Close.
Step 2
Paste below mentioned formula in last helper column XFD (I am assuming you are not using this column)
=CONCATENATE("='[Test.xlsx]",$A1,"'!$A$1")
In B1 enter this formula and drag it down:
=EVALXFD
That's it.
Use the INDIRECT() function. E.g., with $A$1 = 2, $A$2 = 3, ..., you can use
=INDIRECT("'[test.xlsx]"&B1&"'!$O$117")
which Excel will concatenate =INDIRECT('[test.xlsx]2'!$O$117) and then evaluate.
Note also that I've written the references above based on copying the formula down column B (with references in column A), so the row number will change, but the reference will always be to column A.

Determining Cell next to Data Validation based on drop down

So for example let's say we have a Data Validation drop down in sheet Main in cell B2 using Barney, Jack, Moe.
In C2 I want a cell that displays a number.Sheetname based on the Data Validation.
Barney = 1.Main
Jack = 2.Main
Moe = 3.Main
How would I do this?
If I do =CELL("address", b2) it will give me 2
I am assuming that "Barney","Jack","Moe" is just an example. You may have a longer list? If yes, then for this you have to first create the data validation appropriately.
For demonstration purpose, I am placing your list G2,G3,G4 and then selecting them and giving them a name.
Next create the data validation in cell B2 as shown below.
Put this formula in cell C2
=IFERROR(INDEX(MATCH(B2,Names,0),1,1) & ".Main","")
and you are done :)
In C2 enter:
=LOOKUP(B2,{"Barney","Jack","Moe"},{1,2,3}) & ".Main"

Resources