How can i export data from an 'edit text box' in app designer to an excel file?

Hi,
So i want to export the variables below (in the edit text boxes) to an excel spreadsheet. But i am not sure how to to it.
I want to create a callback function fot the 'save data' button, so that when it is pressed, the data is saved to excel spreadsheet.
Can anyone give me some advice on how to do this?
Thanks in advance, Grace

Answers (1)

I assume that you have properties linked to each of these values.
In the callback, you can create a structure or a table involving all what you want, and write them to excel once.
For example,
tbl = table(yourApp.TimeTaken, yourApp.MaxHeight, yourApp.Horizontal, ...
'VariableNames', {'TimeTaken', 'MaxHeight', 'Horizontal'});
writetable(tbl, yourOutputDir);
In above example, I assue the handle of your app is your App, and the property names corresponding to the first three edit boxes are TimeTaken, MaxHeight, Horizontal.
If you didn't link them to a seperate property, you can manipulate through accessing the Value property of the corresponding text edit, e.g.,
tbl = table(yourApp.TimeTakenEdit.Value, ...)

5 Comments

Thanks for the information, you are write i do have properties linked to each value but I didn't link them to a seperate property, so ive done what you advised and manipulated them by accessing the Value property of the corresponding text edit.
I created an excel document called 'Projectilesimulationdata'
but when i type it in i get this error, is there a specific way im supopose to write the filname?
Thanks, Grace
this should be a string or char array. For example, if you want to same to myexcel.xlsx, you use writetable(tbl, 'myexcel.xlsx');
you can always have a full path name as well in addition to the file name. for example, writetable(tbl, fullfile(somedirectory, 'myexcel.xlsx'));
It still isn't saving. Does my excel file have to be saved into a particular place?
i am not getting any errors when i press the save button so it must be saving somewhere right? but its not saving to my file.
What did you use for the second parameter of writetable?

Sign in to comment.

Products

Release

R2020a

Tags

Asked:

on 10 May 2020

Commented:

on 10 May 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!