Read an excel file from excel file
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
I have an excel file in which one of the column contains the names of another excel files. What I am trying to do is 1st using xlsread opening the file that contains the list in and then in a loop I am trying to open each of these excel files one by one,do some calculations and show its result in the row where its file name is stored. My two files looks like this :
1st file :
Origin Date (Local)  Origin Time (Local)       File name
                                            file1
                                                  file2
                                                  file3
2nd file (file1):
 OriginTime  Year  Month  Day  Hour  Minute  Second
51.65086761  2014  6  10  12  9  5.991625
53.03222393  2014  6  10  12  9  5.991625
52.47999444  2014  6  10  12  9  5.991625
52.55764572  2014  6  10  12  9  5.991625
52.73042468  2014  6  10  12  9  5.991625
and similar data in file2 and file3.
I did start a little but I don't know where I am wrong in the code below:
 orginf = '1st file location';
 destfold = 'folder containing the three excel files...file1,file2,file3';
 for n = 1:5
 sheet = 'Sheet1';
 xlRange = ['U' num2str(n+1)];
[~,namefile] = xlsread(orginf,sheet,xlRange);
 sfile = strcat(destfold,namefile,'.xlsx');
 [~,~,ofile] = xlsread(sfile);
It says error in line xlsread(sfile)...filename must be a string.
0 Commenti
Risposte (1)
  Iain
      
 il 6 Ago 2014
        namefile is a cell array. You need to address it like this:
 namefile{3,5}
You'll need to check if the file exists, if there is a file name actually there, etc.
2 Commenti
  Iain
      
 il 7 Ago 2014
				This is what I'd do:
 [numbers text raw] = xlsread(orginf, sheetno); % read the whole sheet.
 column = 21; % U is the 21st letter of the alphabet isn't it?
 for i = 1:size(raw,1) % for each column...
  a = dir(raw{i,column});
  if numel(a)
   [~,~,ofile] = xlsread(raw{i,column});
   ... do stuff
  end
 end
namefile{3,5}, now I've realised that you're reading out a single cell at a time would be wrong, it would be:
sfile = strcat(destfold,namefile{1,1},'.xlsx');
Vedere anche
Categorie
				Scopri di più su Spreadsheets in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

