필터 지우기
필터 지우기

How can I write data to excel without overwrite data that already in the excel ?

조회 수: 1 (최근 30일)
Hi, please help me .
Here is my code:-
filename = 'F:\FYP\Training.xls';
A = {person,A,B,EuclideanDistance,r};
sheet = 1;
xlRange = 'A2';
xlswrite(filename,A,sheet,xlRange)
I want my new data to be insert to the last row(empty row) in that training file.

채택된 답변

Shubham Gupta
Shubham Gupta 2019년 10월 3일
To write in the empty rows, you have to specify that to xlswrite. So, either you know the row number beforehand and use that 'xlRange' to write the variable 'A'. Example:
filename = 'F:\FYP\Training.xls';
A = {person,A,B,EuclideanDistance,r};
sheet = 1;
empty_row = 10
xlRange = ['A',num2str(empty_row)];
xlswrite(filename,A,sheet,xlRange)
Or if you don't know the row number beforehand you can count the filled rows inside the file using xlsread. Example:
filename = 'F:\FYP\Training.xls';
A = {person,A,B,EuclideanDistance,r};
sheet = 1;
[~,~,ev] = xlsread(filename,sheet); % ev is cell array containing every filled row and column
empty_row = size(ev,1) + 1;
xlRange = ['A',num2str(empty_row)];
xlswrite(filename,A,sheet,xlRange)
I hope it helps !

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by