Renaming an Excel Sheet Name in 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).

Upvotes: 5

Views: 19732

Answers (2)

yuk
yuk

Reputation: 19870

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.

Upvotes: 6

Francis P
Francis P

Reputation: 13655

Quick link that should help you get it done:

http://www.mathworks.com/matlabcentral/fileexchange/4474-xlsheets/content/xlsheets.m

Upvotes: 3

Related Questions