Can i save excel files in app designer
7 views (last 30 days)
Show older comments
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
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.
Accepted Answer
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
0 Comments
More Answers (1)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!