Converting a CSV into a XLS through MatLab

조회 수: 38 (최근 30일)
Frank
Frank 2011년 5월 10일
편집: Walter Roberson 2017년 3월 17일
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

채택된 답변

Andy
Andy 2011년 5월 10일
You could import it (in various ways: csvread, import, etc.) and then write out to Excel via xlswrite.
  댓글 수: 5
Walter Roberson
Walter Roberson 2011년 5월 10일
You probably want to tell xlswrite() what you want written ;-)
Andy
Andy 2011년 5월 10일
Good catch, sorry:
[dummy, dummy, raw] = xlsread('filename.csv')
xlswrite('filename.xls',raw)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 5월 10일
Why bother? Open the .csv file in Excel and save it as .xls.
  댓글 수: 7
Walter Roberson
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
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
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---------------------']);

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by