Copy a sheet from template excel & fill the data to the copied sheet
8 views (last 30 days)
Show older comments
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')
hold("on");
copyfile("Template_Excel.xlsx","SSE_Report.xlsx");
Answers (2)
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;
delete(outputFile)
end
% Create an output file based on the template.
copyfile(templateFile, outputFile);
else
% 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);
uiwait(warndlg(warningMessage));
end
% Now create all your data and write it out in one or more writematrix or
% writetable commands.
writetable(yourDataTable, outputFile);
12 Comments
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...
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!