I want to write daily datum into xls file without overwriting

2 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2019-1-8
编辑:Jan 2019-1-8
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 个评论
Omer Yasin Birey
Omer Yasin Birey 2019-1-8
编辑:Omer Yasin Birey 2019-1-8
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 2019-3-21
[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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by