Need help for export table to excel
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everyone,
I have a 1*125 cell named "C" which has 125 tables. I want to export all these 125 tables to separated xlsx files (every table has specific xlsx file). I want the name of each xlsx file to be the first good value (because of a probably empty cell in the first) in the second column (station name). I was try to do this:
Behzad = cell2table (C);
writetable(Behzad,'test.xlsx','Sheet',1);
but after do that the texst.xlsx conatin nothing but C1, C2, C3 which I don't know what that means.
Thank you
0 Commenti
Risposta accettata
Star Strider
il 13 Gen 2020
I am not certain what your cell array consists of.
This prototype code (that appears to construct ‘C’ to match your description of it) works correctly for me:
C = {array2table(rand(4)), array2table(randn(3))}; % Create ‘C’
for k = 1:numel(C)
writetable(C{k},sprintf('test%03d.xlsx',k))
end
I verified that the Excel tables were written correctly. (Now, I am going to delete them.)
6 Commenti
Star Strider
il 13 Gen 2020
As always, my pleasure!
I misunderstood what you wanted.
Try this:
D = load('C.mat');
C = D.C;
for k = 1:numel(C)
filename = C{k}{1,2};
if ~isempty(filename{:})
sprintf('%s.xlsx',filename{:})
writetable(C{k},sprintf('%s.xlsx',filename{:}))
end
end
The ‘filename’ assignment takes the first row element in the second column to use as the file name. The code skips over the tables that are empty in that column, and only write files for those with strings in that column. If I understand correctly, that should do what you want.
Più risposte (0)
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!