I have 10 excel files, i want the name of each excel file.
조회 수: 2 (최근 30일)
이전 댓글 표시
I have 10 excel files, i want the name of each excel file.
Thanks in advance
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!