Changing the name of the sheet in excel

170 ビュー (過去 30 日間)
Gopalakrishnan venkatesan
Gopalakrishnan venkatesan 2015 年 5 月 8 日
コメント済み: qing sheng 2022 年 1 月 27 日
I want to change the names of sheets in excel and then i need to perform the write operation on those sheets?
Is it possible to do with xlswrite?

採用された回答

Thomas Koelen
Thomas Koelen 2015 年 5 月 8 日
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.
  6 件のコメント
Laura Stewart
Laura Stewart 2020 年 9 月 10 日
Be warned if using @Enri solution it will populate the data to the Excel File as text.
This was problematic as I was exporting a matrix of cells with Excel functions (so the Excel user could open the file and easily track and modify the cell values if needed) and once the data was in Excel the cells had to be modified to a number type, then clicked & modified (space added then deleted), and entered one-by-one to show the function value.
qing sheng
qing sheng 2022 年 1 月 27 日
Hi! I am new to coding, when I using it in a for loop, it broke and warned me error code 0x800A01A8. So could you please find me a solution?

サインインしてコメントする。

その他の回答 (1 件)

Ilias Patsiaouras
Ilias Patsiaouras 2019 年 9 月 9 日
Is this code portable for linux and Windows cause I think linux doesnt have ActiveX

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by