Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming an Excel Sheet Name in Matlab

Tags:

excel

matlab

I am creating an Excel using the Matlab xlswrite function. How can I change the name of the first sheet of this Excel document? (I have read the official matlab help, but I haven´t found any solution).

like image 249
Luis Andrés García Avatar asked Mar 23 '12 13:03

Luis Andrés García


1 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 while testing, it overwrite the original file. Make a backup.

like image 146
yuk Avatar answered Sep 29 '22 18:09

yuk