Rename Excel sheet name in Matlab

I am creating Excel using the matlab xlswrite function. How can I change the name of the first sheet of this excel document? (I read the official help at Matlab, but I did not find any solution).

+5
source share
2 answers

You can use ActiveX directly from MATLAB:

xlswrite('test.xls',1) % # create test file

e = actxserver('Excel.Application'); % # open Activex server
ewb = e.Workbooks.Open('c:\test\test.xls'); % # open file (enter full path!)
ewb.Worksheets.Item(1).Name = 'new name'; % # rename 1st sheet
ewb.Save % # save to the same file
ewb.Close(false)
e.Quit

Be careful during testing, it overwrites the original file. Make a backup.

+6
source

All Articles