Reading multiple excel files from a folder that has other types of files in addition to excel and putting the values in a cell array

1 回表示 (過去 30 日間)
I have a folder in which there are files of many types(.csv,.xlsx,.jpg,.mat,etc.) and my objective is to filter out only the excel files, read the values of third column(C) of each excel file and put them into the matrix or cell array.
I don't have any idea on how to write a program that will only read excel files. Below is the following code I wrote using actxserver.
function startServ1
exl = actxserver('excel.application');
exlWkbk = exl.Workbooks;
folder='C:\Users\shankyaw\Desktop\plot';
FilteredFiles = dir([folder '/*.xlsx']);
sd = length(FilteredFiles);
N_File = numel(sd);
%exlData = cell(1,N_File);
for e = 1:N_File
exlFile = exlWkbk.Open([folder '/' FilteredFiles(e).name]);
exlSheet1=exlFile.Sheets.Item('sheet1');
robj = exlSheet1.Columns.End(4);
numrows = robj.row;
dat_range = ['C1:C' num2str(numrows)];
rngObj(:,e) = exlSheet1.Range(dat_range);
end
exlData = rngObj.Value;
exl.registerevent({'WorkbookBeforeClose',@close_event1});
end % startServ1
Can someone help me how to get this reading done. Thanks.

採用された回答

Stalin Samuel
Stalin Samuel 2015 年 8 月 3 日
sdirectory = 'D:\EXAMPLE_directory';
tifffiles = dir([sdirectory '/*.xlsx']);
sd = length(tifffiles);
for k = 1:numel(sd)
File1 = [sdirectory '/' tifffiles(k).name];
A = xlsread(File1)
end
  1 件のコメント
Ye
Ye 2015 年 8 月 3 日
Thanks a lot. do you know how to do this using actxserver instead of xlsread? xlsread is not very ideal for my project because xlsread is very slow.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by