xlswrite in compiled program does not work.

3 views (last 30 days)
I have a problem with a standalone application made with the Matlab compiler. The code in question is
function test
toXLS = cell(3,3);
toXLS{1,1} = 'Abcd';
toXLS{1,2} = 25;
toXLS{2,1} = 'Defg';
toXLS{2,2} = 33;
% generation of output GUI - I left out the part where this is filled with data
report=figure('Name','Calculation Results','NumberTitle','off');
% generate pushbutton in report to save to xls
buttonSave = uicontrol(report,'Style','pushbutton','Units','normalized','String','Export to XLS',...
'Callback',@report2xls,'Position',[0.02 0.02 0.46 0.10]);
% then a nested function to execute the saving of the data
function report2xls(varargin)
[Save2File,Save2Path] = uiputfile('*.xls','Save As...','OGU.xls');
Filename = fullfile(Save2Path,Save2File);
xlswrite(Filename,toXLS);
end
end
This works just fine when I run it in Matlab, I get a nice Excel file with the cell array data. However, after compiling it takes ages for the xls file to be written (I am talking about 5 min+ on a Quadcore i7) and the generated file is empty. Any ideas what my mistake is?
I have both Office 2010 and Office 2013 installed on the computer, might this be a source of error? Also, after invoking the function above an Excel process remains open in the task manager indefinitely.
Thanks a lot for your help,
Sieghard

Accepted Answer

Sieghard
Sieghard on 4 Jan 2017
I finally found a solution. xlswrite seems not to be working properly in compiled programs, so I converted the cell array to a table and used writetable. This works fine, i.e. use
toXLStable = table(toXLS);
writetable(toXLS,Filename,'WriteVarNames',false,'FileType','spreadsheet');
instead of
xlswrite(Filename,toXLS);
in my code above.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!