MATLAB Answers

I want to write daily datum into xls file without overwriting

64 views (last 30 days)
Omer Yasin Birey
Omer Yasin Birey on 8 Jan 2019
Commented: Jan on 21 Mar 2019
Hi All, I have a daily results of some events, which I update them every day and save the previous values as well. Here, I don't want to overwrite the previous values and add the every new date's datas at the end of previous day with their hour and the date of the day. How can I do it in a universal way, so only one run will be enough to store every days data accordingly?
row_headerSecond = {'01.00', '02.00', '03.00', '04.00', '05.00', '06.00', '07.00', '08.00', '09.00', '10.00',...
'11.00', '12.00', '13.00','14.00','15.00','16.00','17.00','18.00','19.00','20.00','21.00','22.00',...
'23.00'};
row_headerFirst = repelem({datestr(today)},23);
xlswrite('myfile.xlsx', data, 'Sheet1', 'C2');
xlswrite('myfile.xlsx',row_header','Sheet1','B2'); %Write row header
xlswrite('myfile.xlsx',row_header1','Sheet1','A2');
Thanks in advance

  0 Comments

Sign in to comment.

Accepted Answer

Jan
Jan on 8 Jan 2019
Edited: Jan on 8 Jan 2019
To append data to an XLS and XLSX file, you have to import the existing data at first to find out, which rows is used already.
Num = xlsread('myfile.xlsx')
Len = size(Num, 1);
New = sprintf('C%d', Len + 1); % Or which range you mean
It is much easier to implement such logging in a text file. Then you can simply append new lines.

  2 Comments

Omer Yasin Birey
Omer Yasin Birey on 8 Jan 2019
Yes, thank you Jan that works. Since I already know(in my mind) which rows is used already, reading the xlsx file is a one more burden for code to do. Therefore, I found a different way too. I am going to write it for people to see an alternative way.
day = datestr(today);
day = strsplit(day,'-');
day = st2double(day{1});
daily = string((double(day)-1)*23+2);
xlRange = string(strcat('B',string(daily)));
Jan
Jan on 21 Mar 2019
[MOVED] Sajid Afaque wrote:
what should i do if i have to write to the next line of a excel sheet..?
@Sajid: This is not an answer. Please post comments in the section for comments or as a new question.
My answer contains a method to define the start position as the first line under the existing data. This should solve your question already. So please post your code and explain, what is not clear yet.

Sign in to comment.

More Answers (0)

Sign in to answer this question.