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

조회 수: 6 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2013년 7월 8일
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;

채택된 답변

MathWorks Support Team
MathWorks Support Team 2013년 7월 8일
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;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB の COM オブジェクト에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!