Can i save excel files in app designer

20 views (last 30 days)
Hello,
In my app i have push button and want the to save a 8 excel files with in the app. Reason for this is as the user makes his/her desired selection prior to using this push button (export) based on the users selection i want one the template(excel file) to be choosen which ever is assigned to the condition and selection made by the user. Please let me know if i could save excel files within an app?
Thanks
Sai
  2 Comments
Guillaume
Guillaume on 21 Oct 2019
Of course, you can. You can use writetable or xlswrite. However, it's very unclear what it is you're wanting to save so we can't really tell you how to do it.
Sai Gudlur
Sai Gudlur on 21 Oct 2019
I understand i can write data out to a excel file. But i want to save excel files within the app itself and call them when i need. For example if i write a code in workspace calling a specific file. Specific file here is abc.
A = uigetfile('abc.xlsx');
[~,~,B] = xlsread(A);
Now this file if it is in the working directory would be called and i would be able to access data.
But when non matlab users use this app would not have access to workspace and i know app does not need matlab workspace to be used. I understand i can add those files while compling the app but in this case i am building an app where user makes a few selections in the first Tab and then when he gets to the second tab and would use a pushbutton and have an template (excel sheet) spit out based on the selections made on the first tab.
There are two ways i could go about
First: make use of the selections made my the user construct a table and have it layed out on an table and write on a excel sheet.
Second : Since i already have the Templates (excel files) which the user is looking for I want to save these files within the app and then based on the selection filter for the right template using Switch or if and have the desired template written out.
I hope my question/query is clear now. Please lemme know other wise.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 22 Oct 2019
You can save any variable of your App to excel, using either xlswrite or writetable.
%... in the app class
function SaveToExcel(app) %possibly as a callback to some button
folder = app.ExcelFolder; %for example
filename = app.ExcelFilename; %for example
xlswrite(fullfile(folder, filename), app.somevariable);
end
If you want to save several variables to excel, you can either group them together in a table or cell array (preferred) or write them in sequence through multiple calls to xlswrite/writetable (slower).
Similarly, you can load the content of an excel file into any variable of your app. Note that if you're using something like a uilistbox to let the user select one of several templates, you would use neither if nor switch to actually load the file. Indexing is a lot simpler and flexible.
%creation of the uilistbox in the CreateComponent method or the StartupFcn callback
app.listboxTemplate = uilistbox(app.Figure, ...
'Items', {'Template for aaa', 'Template for bbb'}, ... stuff to display
'ItemsData', {'template1.xlsx', 'template2.xlsx'}); % actual file to load
%in the function that loads the template. Possibly a callback
function LoadTemplate(app)
folder = app.ExcelFolder;
if ~isempty(app.listboxTemplate.Value)
app.ExcelTemplate = xlsread(fullfile(folder, app.listboxTemplateValue)); %the list box value is the content of ItemsData for the selected entry
else
uialert(app.Figure, 'No template selected');
end
end

More Answers (1)

Sai Gudlur
Sai Gudlur on 22 Oct 2019
Thanks a lot Guillaume for your suggestion.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!