Converting a CSV into a XLS through MatLab
51 ビュー (過去 30 日間)
古いコメントを表示
Hello
I have a large set of data that is formatted in .csv and I was wondering if there was a way through MatLab that could convert it to an .xls.
Thanks,
-Frank
source_dir = 'C:\Users\xuf\Desktop\Raw Data (CSV)'
dest_dir = 'C:\Users\xuf\Desktop\Converted Raw Data (Excel)'
source_files = dir(fullfile(source_dir, '*.csv'));
for i = 1:length(source_files)
data= csvread(fullfile(source_dir,source_files(i).name));
xlswrite(fullfile(dest_dir,source_files(i).name), data);
end
0 件のコメント
採用された回答
その他の回答 (2 件)
Fangjun Jiang
2011 年 5 月 10 日
Why bother? Open the .csv file in Excel and save it as .xls.
7 件のコメント
Walter Roberson
2011 年 5 月 10 日
How much time spent coding and debugging the actxserver() version? How much time spent executing xlsread() and xlswrite() for 20 files?
Fangjun Jiang
2011 年 5 月 10 日
I don't want to get into an argument here. But for using actxserver(), it needs one command to open the server at the beginning and one command at the end to delete it. For each loop, one command to open the csv file and one command to save as .xls file.
The time save would be huge if the Excel file is large.
In terms of debugging, that will depends on your experience, right?
At issue is taking the right approach to tackle the task.
Harish TV
2017 年 3 月 17 日
編集済み: Walter Roberson
2017 年 3 月 17 日
clear;
clear all;
fileip='filename.csv';
g=char(fileip);
g=g(1:end-4)
fileop=horzcat(g,'.xlsx')
g=fileip(1:end-4);
[~,~,F]=xlsread(fileip);
F=cellstr(F);
%delete the header rows (4 rows)
F([1:4],:)=[];
for a=1:size(F,1);
b=F(a,1);
c=char(b);
D(a,:)=strsplit(c,',');
end
xlswrite(fileop,D);
disp(['--------------Process complete---------------------']);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!