I have been playing around with google sheets integration.
I can get the values for a row if I know the column name.
How do I return a row without knowing the exacting columns, is there a get_row function.
I tried using ‘list_rows’ doing the following but it failed
db=app_files.update
print(db['[STOCK UPDATE'].list_rows)
In another thread, I was seeking documentation on how to use the following, but it was unanswered.
The help files only list getting rows.
ie How how returning all records as a list of lists for inputting into a data frame.
or how to use ie for the following.
[‘_obj’, ‘add_row’, ‘creds’, ‘get_cell’, ‘get_fields’, ‘list_cells’, ‘list_rows’]
I am no master in these things but from what I can see in this
your square brackets are unbalanced.
Additionally can you link to the other thread which was unanswered?
That might help some of the people who knows more about the problem to solve both problems.
All the beste jesper
good question.
The docs on google sheets could certainly do with an update.
And the auto-completer could do with some enhancements.
For example
db = app_files.my_file
ws = db['Sheet1']
if we do:
for row in ws.list_rows():
row
We get a SuspensionError
in the client but not in a ServerModule
instead, in the client do:
for row in ws.rows: # which is also probably preferred on the server too
row
rows
isn’t in the dir
or in the auto-complete but it is in the documentation
whereas list_rows()
isn’t in the documentation but is in the dir

in short list_rows()
is a generator object (which is confusing since the method is called list_rows()
) where as ws.rows
is anvil._server.LiveObject
in the server and a list
in the client.
Anyway - the point is that it could certainly do with some improved documentation and examples since it’s very easy to stub your toes when working with anvil’s google sheets api.
My approach is largely, docs and trial and error with a lot of dir()
thrown in.
for your question about how do you work with a row if you don’t know its fields
you could do…
db = app_files.my_file
ws = db['Sheet1']
fields = ws.fields # or ws.get_fields() :-|
for row in ws.rows:
row_dict = {field:row[field] for field in fields}
2 Likes