MATLAB: How to save diary to xls or xlsx

MATLABsave command window.xlssave diary as xls

I have created a script with functions that allows a user to input the name of two planets which returns data relating to the two.The following fprintf lines display the output information for a user.
diary diary
fprintf('\n')
fprintf('The mass of %s is: %d e+24 kg\n',CB1,m1)
fprintf('The diameter of %s is: %d km\n\n',CB1,d1)
fprintf('The mass of %s is: %d e+24 kg\n',CB2,m2)
fprintf('The diameter of %s is: %d km\n\n',CB2,d2)
fprintf('The distance from the centre of %s to the centre of %s is: %d km\n\n',CB1,CB2,ConAU)
fprintf('The Gravitational force between %s and %s is: %d N\n\n',CB1,CB2,N)
Name=['The output data is saved in the excel file: ',CB1,CB2,'.xls'];
disp(Name)
fprintf('\n')
fprintf('Thank you for using PGCalc.')
diary off
File_name=sprintf('%s%s',CB1,CB2);
xlswrite(File_name,'diary');
warning('off','Matlab:xlswrite:addsheet')
—————————————————————————————————————————————————————-
once the variables are input the command window shows:
The mass of Uranus is: 8.680000e+01 e+24 kg
The diameter of Uranus is: 51118 km
The mass of Neptune is: 3.300000e-01 e+24 kg
The diameter of Neptune is: 4879 km
The distance from the centre of Uranus to the centre of Neptune is: 1633632000 km
The Gravitational force between Uranus and Neptune is: 7.822292e-33 N
The output data is saved in the excel file: UranusNeptune.xls
————————————————————————————————————————————————————————–
My issue, is that i need everything in the command window to be saved as a .xls or .xlsx
My effort is to use diary, then use xlswrite (file_name,'diary'). this does save to a .xls but the information does not show, instead it displays :
support.PNG
Can somebody suggest a better method of saving the command window to .xls or .xlsx. Or help fix my current code so it doesnt display d i a r y in the saved excel file.
Thanks in advance.

Best Answer

Of course it does: xlswrite (file_name,'diary') creates an Excel file and inserts the char vector 'diary'.
Why do you try to use the indirection over the diary file? You export the lines directly:
File_name=sprintf('%s%s.xls',CB1,CB2);
Data = {sprintf('The mass of %s is: %d e+24 kg\n',CB1,m1); ...
sprintf('The diameter of %s is: %d km\n\n',CB1,d1); ...
sprintf('The mass of %s is: %d e+24 kg\n',CB2,m2); ...
sprintf('The diameter of %s is: %d km\n\n',CB2,d2); ...
sprintf('The distance from the centre of %s to the centre of %s is: %d km\n\n',CB1,CB2,ConAU); ...
sprintf('The Gravitational force between %s and %s is: %d N\n\n',CB1,CB2,N); ...
sprintf('The output data is saved in the excel file: %s', File_name); ...
''; ...
'Thank you for using PGCalc.'};
xlswrite(File_name, Data);