How to Import excel document with alot of sheets that does not ignore date in first column

3 ビュー (過去 30 日間)
Hi,
I need to import an excel doc that has a lot sheets (individual stocks on each sheet).
I manage to import with the code underneath, but it skips column A on every sheet that is the date. The date are formatted in excel as this : 1/3/2017 etc. If I manually change them to be numbers in excel it works, but that takes too much time in the long-run so I want that MATLAB solves that for me. Any suggestions/help?
[~,sheet_name] = xlsfinfo('filename.xlsx');
for k= 1:numel(sheet_name)
data{k} = xlsread('filename.xlsx', sheet_name{k});
end
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2018 年 9 月 12 日
Please attach here one your xlsx-file.
Kristian Opsahl
Kristian Opsahl 2018 年 9 月 12 日
Hi,
This is a small version of the full file I will use in the end

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2018 年 9 月 12 日
fn = 'Path_to_your_file\MachineLearning.xlsx';
[~,sheet_name] = xlsfinfo(fn);
sheet_name = strrep(sheet_name,' ','_');
S = struct();
for ii = 1:numel(sheet_name)
[d,t] = xlsread(fn,ii);
if ii == 1
vn = t(5,2:end);
vn{13} = strrep(vn{13},'%','PR');
end
t(6,1) = t(1,2);
RTime = datetime(t(6:end,1),'f','dd.MM.uuuu');
S.(sheet_name{ii}) = array2timetable(d,'Rowtimes',RTime,'v',vn);
end

その他の回答 (1 件)

KSSV
KSSV 2018 年 9 月 12 日
I suggest you to use readtable.
With xlsread:
[num,txt,raw] = xlsread(myfile) ;
  2 件のコメント
Kristian Opsahl
Kristian Opsahl 2018 年 9 月 12 日
Hi, Thank you for your answer. With this I am only able to get the first sheet, Not the rest. Am I doing something wrong with my setup then?
KSSV
KSSV 2018 年 9 月 12 日
Read the documentation.....you need to provide the sheet number which is to be read.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by