Spreadsheet component. Example. Google Sheets

In order to utilize this component, one must first have a Google Developer Account. Then, one must create a new project under that Google Developer Account, enable the Google Sheets API on that project, and finally create a Service Account for the Sheets API.

How to create the Service Account, here:
http://ai2.appinventor.mit.edu/reference/other/googlesheets-api-setup.html

At the end of the whole process we will obtain a file of the form:
app-inventor-338017-8c72fd465555.json

We must upload that file to our application.

Let's look at an example:

p138_googlesheet_2.aia (5.9 KB)****[This app doesn't work because the identifiers are fake keys.]

3 Likes

no entendí nada te puedo enviar un mensaje privado con mi archivo aia?

First you need the json file which you can get at...

create the Service Account:
http://ai2.appinventor.mit.edu/reference/other/googlesheets-api-setup.html

entonces tengo que cambiar todo el codigo de la aplicacion
no puedo usar el anterior acabo de cambiar un archivo de Excel,
te puedo dar el archivo en privado?

Hola, buenas tardes. Estoy empezando a usar el componente SpreadSheet y he seguido todos los pasos para obtener el archivo .json y las credenciales. Tengo un archivo creado con los permisos otorgados (el usuario que me da la cuenta de servicio), pero en App Inventor, cuando voy a emular la aplicación, me da el fallo "Runtime Error. Cannot find the component: SpreadSheet1". He revisado todo paso a paso e incluso he probado con su ejemplo (cambiando el archivo .json por el mío y poniendo el ID correcto de mi hoja de cálculo) pero me ocurre lo mismo. ¿Sabe por donde puede venir el fallo?

Saludos

What version does your MIT Companion have?
Upgrade to 2.65

Hola de nuevo. En efecto, ese era el problema. Muchas gracias por contestar. Saludos!!

Hola, buenas tardes! Estoy haciendo una pequeña app y me encuentro con algunas dudas. Gracias a su ejemplo he aprendido mucho acerca del componente Spreadsheet, pero, en caso de tener una columna con 50 items que he rellenado manualmente desde el ordenador, por ejemplo, y quiero añadir uno nuevo, ¿cómo hago para añadirlo en una celda vacía (la 51)? ¿Se puede hacer con bloques o habría que hacer un script?

With WriteCell
A51

Gracias por su respuesta. Pero, en el caso de que la aplicación no sepa qué celda está vacía en ese momento (podría ser la A50, o cualquiera), ¿se podría programar por bloques la búsqueda de la celda libre disponible (he visto que el componente Spreadsheet tiene muchos recursos pero no encuentro ningún ejemplo para basarme en él) o habría que acudir a un script (un bucle for para hacer un recorrido de búsqueda)?

Saludos

I believe you use the AddRow method to append a new row of data to the first empty row of the worksheet.

1 Like

getreference

Got:
A1
B1:D3

  • You can get the number of items in a column by ReadCol

1 Like

I'm using the WriteCol function but advice error in the app saying "The operation WriteCol cannot accept the arguments: ,["Sheet1"],[2], ["John"]

What means that? I cannot send datatext from some variable, is just for using as a list?

Like so

image

I am trying to identify why my app will not write to my Google sheets file. I have set everything up in Google Cloud. Here are my blocks and the error message I receive on my phone when using the emulator.


Set CredentialsJson is expecting a file, you are providing a code.

Set Spreadsheet ID is expecting a Spreadsheet ID, you are providing a file path

I made the corresponding changes but I am still getting an error. Attached are my blocks and the error that I am receiving.


Have you tried setting the credentials file in the Spreadsheet component designer properties ? (and the Spreadsheet ID for that matter)

If you do try this, remove or disable the setting blocks in your blocks editor.

image

I ran a test, using my own credentials and spreadsheet. This works OK

image

image

more work to do at your end....

There also seems to be some kind of bug with the join block

This works

image

This works

image

but this fails (which is what you are doing in your blocks)

image

@Susan_Lane

error message:
WriteColumn IOException: 400 Bad Request PUT https://sheets.googleapis.com/v4/spreadsheets/1IdpGILd7Nii111111o5la2xbDN1Cok/values/Sheet74!E:E?valueInputOption=USER_ENTERED { "code" : 400, "errors" : [ { "domain" : "global", "message" : "Invalid values[0][0]: list_value {\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n}\n", "reason" : "badRequest" } ], "message" : "Invalid values[0][0]: list_value {\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n values {\n struct_value {\n }\n }\n}\n", "status" : "INVALID_ARGUMENT" }

This is a workaround, by first setting the joined text to a label, then the label text to the make list block in the WriteColumn method (the label does not have to be visible). Just setting the join output to a local variable doesn't work.

image