필터 지우기
필터 지우기

I have 10 excel files, i want the name of each excel file.

조회 수: 2 (최근 30일)
Mohammad Abu Zafer Siddik
Mohammad Abu Zafer Siddik 2016년 11월 20일
댓글: Walter Roberson 2016년 11월 20일
I have 10 excel files, i want the name of each excel file.
Thanks in advance

답변 (1개)

Walter Roberson
Walter Roberson 2016년 11월 20일
%code to find all excel files in a directory
%warning: this code makes no attempt to verify that xml files were produced by Excel
excel_extn = {'xlc', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xlw', 'xml' };
projectdir = 'C:\Where\Your\Files\Are';
num_extn = length(excel_extn);
dinfo = cell(num_extn, 1);
for K = 1 : num_extn
dinfo{K} = dir( fullfile( projectdir, ['*.', excel_extn{K}]);
end
dinfo = vertcat(dinfo{:});
excel_file_names = fullfile( projectdir, {dinfo.name} );
In the special case where only a single excel extension is to be handled, this code could be much shorter.
  댓글 수: 3
Mohammad Abu Zafer Siddik
Mohammad Abu Zafer Siddik 2016년 11월 20일
I have only xls files. 'excel_file_names' does not have anything.
Walter Roberson
Walter Roberson 2016년 11월 20일
projectdir = 'C:\Where\Your\Files\Are';
dinfo = dir( fullfile(projectdir, '*.xls') );
excel_file_names = {dinfo.name};
Be sure to update projectdir to the appropriate directory name.
In the case of wanting to find the files in the current directory:
dinfo = dir( '*.xls' );
excel_file_names = {dinfo.name};
You can cross-check with
ls('*.xls')

댓글을 달려면 로그인하십시오.

카테고리

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