필터 지우기
필터 지우기

Rename titles of sheets for xlswrite

조회 수: 5 (최근 30일)
JB
JB 2017년 9월 18일
답변: Walter Roberson 2017년 9월 18일
I need a bit of help to rename my tabels for xlswrite. I try to use the below code which work as long as the title names are different. However, when I have to identical titels like 'table1' in the example it won't work. How can I search the title strings and if two are identical give them an additional number so my Title array becomes Title={'table1 (1)'; 'table2'; 'table3'; 'table4'; 'table1 (2)';}.
Here is my code
Title={'table1'; 'table2'; 'table3'; 'table4'; 'table1';}
[FileNameBodeWrite,PathNameBodeWrite] = uiputfile({'*.xls'},'Save As', [ '.xls']);
filename=[PathNameBodeWrite FileNameBodeWrite];
t=1/numel(Table);
for ii = 1:numel(Table)
sheet=ii;
xlswrite(filename,Table{ii},sheet,'A1');
e = actxserver('Excel.Application'); % # open Activex server
ewb = e.Workbooks.Open(filename); % # open file (enter full path!)
ewb.Worksheets.Item(ii).Name = Title{ii,1} % # rename sheets
ewb.Save % # save to the same file
ewb.Close(false)
e.Quit
end

답변 (1개)

Walter Roberson
Walter Roberson 2017년 9월 18일
xlsinfo() can tell you the current names of the sheets.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by