Copy a sheet from template excel & fill the data to the copied sheet

8 views (last 30 days)
i have created a small matlab app in which i have an issue with copying data
The issue is i have an excel template & i want to copy the excel template , then fill the data in that template, it works within matlab but once i convert it into desktop app, it only copies the template & it doesn't fill in the data, Kindly help me resolve this
Thanks in advance :)
[filename,folder] = uiputfile("SSE_Report.xlsx");
tblRH = table(app.RHFTorque90AngleEditField.Value,app.LHRTorque90AngleEditField.Value,'VariableNames',{'R','L'});
writetable(tblRH,fullfile(folder,filename),'Sheet','Static Steering Effort','Range','F22:G23',AutoFitWidth=false)
tblCentre = table(app.FTorque0AngleEditField.Value,app.RTorque0AngleEditField.Value,'VariableNames',{'R','L'});
writetable(tblCentre,fullfile(folder,filename),'Sheet','Static Steering Effort','Range','F19:G20',AutoFitWidth=false)
tblLH = table(app.RHFTorque100AngleEditField.Value,app.LHRTorque100AngleEditField.Value,'VariableNames',{'R','L'});
writetable(tblLH,fullfile(folder,filename),'Sheet','Static Steering Effort','Range','F25:G26',AutoFitWidth=false)
xlswritefig(app.UIAxes2,fullfile(folder,filename),'Static Steering Effort','C18')
Kavinprasad M
Kavinprasad M on 7 Oct 2022
i understand that and even with copying the template before & writing the data , it doesn't work that way. it only executes writing the data whereas copying the template is missing.
As for creating it in one matrix, i understand but in future it is to be edited & copied in different sheets so i meant to seperate them now to reduce hassle
Is there any other way to make this work?, please let me know

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 7 Oct 2022
Edited: Image Analyst on 7 Oct 2022
You need to have copy file in advance then write to it.
% Ask use for a filename for our output data
[filename,folder] = uiputfile("SSE_Report.xlsx");
outputFile = fullfile(folder, filename)
% Define the tamplate Excel workbook.
templateFile = fullfile(programFolder, 'Template_Excel.xlsx')
% Copy over template file, if it exists, to output file.
if isfile(templateFile)
% Get rid of any existing file. Put it in the recycle bin.
if isfile(outputFile)
recycle on;
% Create an output file based on the template.
copyfile(templateFile, outputFile);
% Let user know we didn't find the template. You will still get an
% output file though, though not one based on the template.
warningMessage = sprintf('Warning: template file not found:\n%s', templateFile);
% Now create all your data and write it out in one or more writematrix or
% writetable commands.
writetable(yourDataTable, outputFile);
dpb on 9 Oct 2022
"you have write permission to the outputfile location"
I've run into all kinds of OS-set access problems on Win10 that I don't fully understand just what it does and why/how and particularly how to beat it into submission in writing to locations containing executables; it appears by default install on it makes those require Admin privileges. I wonder if the MATLAB distribution of the executables is doing something of that sort as well; I've not tried to deploy a compiled app on this machine; on the uni machine for which I wrote a couple apps I had to have IT log in to be able to even get the executable on the system; it was locked down so tightly couldn't even copy over the testing directory from local machine...

Sign in to comment.

Kavinprasad M
Kavinprasad M on 10 Oct 2022
Even without the xlswritefig, it seems to have some issues with excel as a standalone app in windows 11. i have template file as .xlsx, i'll change the way i aquire data from table & try it again
Thankyou guys >.<

Community Treasure Hunt

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

Start Hunting!

Translated by