Find the missing rows and newly added rows in two different excels sheets

3 次查看(过去 30 天)
Hello
I am comparing and finding out the missing rows and newly added rows data from two different excels sheets.
I have attached 3 files.
SummaryNew.xlsx and SummaryOld.xlsx are having data. Compare those 2 excel files.
  • SummaryResult.xlsx In a result, I am expecting 2 sheets. MissingData and NewlyAddedData.
Thank you!!
I tried using
diff_rows = find(all(cellfun(@isequal, SummaryOld', SummaryNew')) == 0);
similar_rows = find(all(cellfun(@isequal, SummaryOld', SummaryNew')) == 1);
bt it is just comparing one excel whole with other.

采纳的回答

Akira Agata
Akira Agata 2022-7-19
How about the following?
% Load the Excel files
tNew = readtable('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1069895/SummaryNew.xlsx',...
'VariableNamingRule','preserve');
tOld = readtable('https://jp.mathworks.com/matlabcentral/answers/uploaded_files/1069900/SummaryOld.xlsx',...
'VariableNamingRule','preserve');
% Newly Added data
idx = ismember(tNew, tOld, 'rows');
tNew(~idx,:)
ans = 2×4 table
PLD Status BLF File Name Time(sec) EgoSpeed(kmh) __________ ___________________ _________ _____________ {'ddd'} {'20220330_143818'} 2495.4 67.9 {'eee'} {'20220330_184617'} 3755.8 88.5
% Missing data
idx = ismember(tOld, tNew, 'rows');
tOld(~idx,:)
ans = 2×4 table
PLD Status BLF File Name Time(sec) EgoSpeed(kmh) __________ ___________________ _________ _____________ {'aaa'} {'20220330_101314'} 2101 56.1 {'bbb'} {'20220330_143818'} 2200 60
  4 个评论
Santosh Biradar
Santosh Biradar 2022-7-21
编辑:Santosh Biradar 2022-7-21
I have one more step need to add in the SummaryResult.
Your responce will be very helpful.
Eg.
In the SummaryResult Excel,
if A3 having value aaa and A6 also having aaa (like the same values present in A Column only) then Entire ROWS MissingData-sheet and NewlyaddedData-sheet will be written separately to new *AAA*Sheet in the Same SummaryResult.xlsx
if A4 having value bbb and A5 also bbb (the same values present in A Column only)then entire ROWS from MissingData-sheet and NewlyaddedData-sheet will be written separately to new *BBB* sheet in the Same SummaryResult.xlsx
I have attached upated Required SummaryResult.xlxs
Please have a look for ref. Sheet AAA and BBB
Thank you

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by