Import data from google sheets to matlab
Mostrar comentarios más antiguos
Hello guys,
I wanted to import data from google sheets to matlab. However I couldn't find any information about it. Since the google sheets always geting update I can't just copy and paste so I wanted to import new data for every time I run the matlab script. Is there a way?
Thanks in advance.
1 comentario
Vinicio Moya
el 26 de Jun. de 2020
Did you resolve it?
Respuestas (3)
Donald
el 4 de Mzo. de 2021
First, find the ID for your Sheet. It's the long string if you look at the URL. For example,
http s://docs.google.com/spreadsheets/d/bladjaljd77442n2j3ljk2j3j2jdkdjad/edit#gid=1498695871
Then it's easy
ID = 'bladjaljd77442n2j3ljk2j3j2jdkdjad'
sheet_name = 'My Sheet';
url_name = sprintf('https://docs.google.com/spreadsheets/d/%s/gviz/tq?tqx=out:csv&sheet=%s',...
ID, sheet_name);
sheet_data = webread(url_name);
7 comentarios
Stuart Mangles
el 12 de Mzo. de 2021
This is great - is there a way to skip the first row? The sheet I am using has header info in the first row and the actual variable names in the second row.
Bennet Den Hoed
el 3 de Ag. de 2021
Stuart,
I am finding that any headers that I have in my Google Sheet get included into the "header" of the MATLAB table (unsure of the technical term - see yellow highlight in screenshot). Only the numeric values are included in the MATLAB table itself, making it 4x2 instead of 5x2.

I am actually interested in having the headers included in the table (5x2 case is desirable for me). I've played around a bit, without much luck.
- Inserting another row of "dummy headers" in row 1 of the Google Sheet: The two strings get concatenated and left in the "header" of the MATLAB table, still.

- Placing the headers at the bottom row of the Google Sheet: These headers are ignored and generic names (Var1, Var2) are instead assigned.

- Creating a table of only characters in the Google Sheet: First row is put into the MATLAB "header" and the body of the MATLAB table becomes the other strings.

It seems that the table must be either all numbers or all strings. Again, I would like there to be a mix of this (5x2 case, with the headers as the first row of the MATLAB table).
Can anyone help me figure out how to do this?
Umair Mughal
el 21 de Dic. de 2021
That's really great, but doesn't work for protected sheets. The url returns the html content of google login page
thierry Lanoe
el 25 de Mzo. de 2023
is there a solution with "protected sheets"
Marcos Hannibal
el 1 de Feb. de 2026 a las 20:06
thierry quitale la proteccion cambiando la opcion de compartir a "cualquier persona que tenga el enlace" en google sheets
Walter Roberson
el 1 de Feb. de 2026 a las 22:45
Thierry, remove the protection by changing the sharing option to "anyone with the link" in Google Sheets.
Hiro Yoshino
el 12 de Dic. de 2019
try
opts = detectImportOptions(filename)
1 comentario
Hüseyin Cagdas Yatkin
el 12 de Dic. de 2019
dimuthu chathuranga
el 9 de Abr. de 2021
0 votos
I have same problem please help me I want to real time uptade data fron google sheet to mathlab gui
1 comentario
Vinicio Moya
el 9 de Abr. de 2021
Editada: Walter Roberson
el 9 de Abr. de 2021
Yes.. you can use this funtion:
Categorías
Más información sobre Google en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!