Converting .xls and .xlsx to .csv
105 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
mike
el 7 de Dic. de 2014
Comentada: Image Analyst
el 22 de Jul. de 2020
Hey guys,
I was wondering if there was a way I could ask a user if their file is .csv, and if not, I would sent it through a loop to have it converted to .csv. Is there any way I could do that?
Thanks!
0 comentarios
Respuesta aceptada
Image Analyst
el 7 de Dic. de 2014
Editada: Image Analyst
el 7 de Dic. de 2014
Why not assume the extension is correct and process it if necessary?
[folder, baseFileName, extension] = fileparts(filename);
if strcmpi(extension, '.xlsx')
numbers = xlsread(filename);
csvFileName = strrep(filename, '.xlsx', '.csv');
csvFileName = strrep(csvFileName, '.xls', '.csv');
csvwrite(csvFileName, numbers);
end
5 comentarios
Vikas Saroha
el 22 de Jul. de 2020
But it writes only numbers not including row and colomn headers. How these can be included in the .csv file?
Más respuestas (2)
Harish TV
el 17 de Mzo. de 2017
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 comentarios
sapna kumar
el 11 de En. de 2019
file = dir('*.xlsx'); % make sure your are navigated to the right folder on matlab
s= size(file,1);
for i= 1:s
Data = xlsread(file(i).name);
filename=file(i).name;
filename= filename(1:end-5); % to remove extension from filename
csvwrite([filename '.csv'], Data);
end
0 comentarios
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!