Converting CSV files to xlsm excel worksheet
2 次查看(过去 30 天)
显示 更早的评论
Hi
I have a folder containing many excel files ( more than 300) in csv format . I need to write all these files in xlsm excel work sheet.
Can this be done in matlab . Can anyone please help.
below, i have attach how the converting looks like.
thank you very much
0 个评论
回答(1 个)
Walter Roberson
2020-9-29
Because you have a mix of datatypes in the file, I recommend that you fopen() each file, and that you textscan() the next two lines with format '%s%s%s%s%s' and 'delimiter', ';' . Save the resulting cell array A for later.
Then textscan() one line with format repmat('%s',1,13) and delimiter ';' . Save the resulting cell array B for later.
Then textscan() the remaining lines with format
['%{hh:mm:ss}T', repmat('%f', 1, 16)]
Save the resulting cell array C for later.
Now let
D = cell(size(C{1},1)+3, 17);
D(1:2, 1:5) = A;
D(3, :) = B;
D(4:end) = num2cell(cell2mat(C));
or something like that.
Now writecell() D if you have R2019b or later.
Or you perhaps might want to work in three sections, writing each section in turn, using the range specifications; the advantage of doing that is that you would not have to fiddle around with padding the arrays out to the widest (17).
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!