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

回答(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 个评论
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')

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by