i have a problem to write to a excel

조회 수: 2 (최근 30일)
Sajid Afaque
Sajid Afaque 2019년 3월 21일
댓글: Sajid Afaque 2019년 3월 25일
hi, i need to write user_id and date in a seperate excel sheet .I want to write it to a new line in my excel document ' instead of overwriting previous lines in my excel document Book11.I just want it to jump a line. Note( I don't know what line I want it to write to, I just want the code to find the previous line in the excel doc and them simply write to the next one). i have a problem with xlswrite in line 8. Please do help i have enclosed the code and the excel sheet.
d = {'usre_id' , date};
[~, user_id] = xlsread('C:\Users\AFQ1KOR\Desktop\newfolder\kkr.xlsx','A:A');
access = ismember('afq1kor' , user_id );
if access == 1
[~, record] = xlsread('C:\Users\AFQ1KOR\Desktop\newfolder\khan2.xlsx','A:A');
q = length(record);
r = q + 1;
xlswrite('C:\Users\AFQ1KOR\Desktop\newfolder\Book11.xlsx',d,'Ar:Br');
end

채택된 답변

Jan
Jan 2019년 3월 21일
You got it almost:
q = size(record, 1); % Safer than LENGTH
r = q + 1;
xlswrite('C:\Users\AFQ1KOR\Desktop\newfolder\Book11.xlsx', d, ...
sprintf('A%d:B%d', r, r);
'Ar:Br' does not insert the contents of the variable r in the char vector. Use sprintf to insert the number to the char vector.

추가 답변 (1개)

Alex Mcaulley
Alex Mcaulley 2019년 3월 21일
Try this:
d = {'usre_id' , date};
[~, user_id] = xlsread('C:\Users\AFQ1KOR\Desktop\newfolder\kkr.xlsx','A:A');
access = ismember('afq1kor' , user_id );
if access == 1
[~, record] = xlsread('C:\Users\AFQ1KOR\Desktop\newfolder\Book11.xlsx','A:A');
if size(d,2)>size(record,2)
record(:,size(record,2)+1:size(d,2)) = deal({[]});
else
d(:,size(d,2)+1:size(record,2)) = deal({[]});
end
xlswrite('C:\Users\AFQ1KOR\Desktop\newfolder\Book11.xlsx',[record;d]);
end
  댓글 수: 1
Sajid Afaque
Sajid Afaque 2019년 3월 25일
thanks alex its working but with slight modification as per my requirements.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2013b

Community Treasure Hunt

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

Start Hunting!

Translated by