excel cells wider in matlab export

I have exported the outputs of the program I´ve done to excel but the cells are in the basic width, can matlab make the cell width automatically wider depending on the width of the values and words in the cell???

Answers (2)

Not by itself, but if you are using MS Windows and have Excel installed, then you can use ActiveX to talk to Excel to send formatting information for the cells.
The direct answer is No. xlswrite() only writes the data. It can't format the Excel file.
You can use actxserver('Excel.Application') to modify the Excel file format. See help on actxserver(). You can set the column width or autofit.
FirstRow.ColumnWidth=20;
FirstRow.Columns.AutoFit;
If you don't want to do that, there is a trick. You can pre-create the Excel file that you want to write to (with the same file name, same sheet name etc), adjust the column width, leave the data sheet blank, save and close the file. Then you can write your data to the file and the format remains.

2 Comments

This solution does not work because writematrix does change the format for the columns in a preformated file.
Do not use writematrix() for this purpose: use xlswrite() on an MS Windows system that has Excel installed.

Sign in to comment.

Asked:

on 26 Apr 2018

Commented:

on 11 Feb 2020

Community Treasure Hunt

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

Start Hunting!