How to combine 3 (or more) separate CSV files into one Excel file with multiple sheets
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
PATRICK WAYNE
am 14 Aug. 2018
Kommentiert: PATRICK WAYNE
am 15 Aug. 2018
Hi everyone,
I have a problem. I have three separate CSV files, all with different headers, that I want to combine into one Excel file with multiple sheets, so that each sheet, of course, represents each CSV file.
I may need to combine more than three later on, but for now, three will do. I do not have any code for this because I honestly have no idea how to start. I know how to read in the files themselves, but combining them eludes me. To create the CSV files, I am using 'csvwrite_with_headers', a file I dopwnloaded a while ago from Matlab Central. The file names are 'Pressdata5050.csv', 'Tempdata5050.csv', and 'Velocitydata5050.csv'.
I would appreciate any help you could provide.
p.s. I'm using R2018a
0 Kommentare
Akzeptierte Antwort
Stephen23
am 14 Aug. 2018
Bearbeitet: Stephen23
am 14 Aug. 2018
D = 'path of folder where the CSV files are';
S = dir(fullfile(D,'*.CSV'));
for k = 1:numel(S)
mat = csvread(fullfile(D,S(k).name)); % or whatever loads your data
xlswrite('merged.xlsx', mat, fileparts(S(k).name))
end
If the CSV files contain text then use xlsread instead of csvread:
[~,~,mat] = xlsread(fullfile(D,S(k).name));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!