Excel ファイルのシート名を変更することはできますか?

4 views (last 30 days)
MathWorks Support Team
MathWorks Support Team on 8 Jul 2013
MATLAB から Excel を利用するために ACTXSERVER を使用しています。ヘルプドキュメントには以下のようなコードがありますが、ワークブック内のシート名を変更する方法がわかりません。
filename = 'C:\SomeExcelFile.xls';
% Open Excel Automation server
Excel = actxserver('Excel.Application');
% Make Excel visible
Excel.Visible=1;
% Open Excel file
Workbook = Excel.Workbooks.Open(filename);
% Get the list of sheets in the workbook
Sheets = Excel.ActiveWorkbook.Sheets;

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 8 Jul 2013
XLSWRITEではシート名の変更はできません。
その代わりに、MATLAB上でExcelのオートメーションサーバーを使用し、シートのオブジェクトの"Name"プロパティにより変更が可能です。
%ファイル名の指定(フルパスで指定)
filename = 'C:\SomeExcelFile.xls';
% Excelのオートメーションサーバーを開く
Excel = actxserver('Excel.Application');
% Excelを表示
Excel.Visible=1;
% ファイルを開く
Workbook = Excel.Workbooks.Open(filename);
% シートのリストを取得
Sheets = Excel.ActiveWorkbook.Sheets;
% シートの名前変更
Sheets.Item(1).Name = 'This is sheet 1';
%ファイルの保存
Workbook.Save();
%後処理
Excel.Quit();
Excel.delete();
clear Excel;
clear Workbook;
clear Sheets;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!