Hi everyone,
The question relates to the use of the use of the actxserver for an excel application.
I'm creating a a standalone to compare two excel tables. The Tables are nearly equal. Every week I'm getting a new excel table. I have to check if there are rows that were cleared.
The actual problem is in the second part of the code but I wanted to show you also the first part to help you to understand what I'm trying to do.
function [] = exc_1_call (varargin)
[S.filename_xlsx_1, S.pathname_xlsx_1] = uigetfile({'*.xlsx'},'');
file = strcat(S.pathname_xlsx_1, S.filename_xlsx_1);
[S.num_1,S.txt_1,S.raw_1] = xlsread(file);
S.excel_1 = actxserver('Excel.Application');
S.excel_1.Visible = true;
S.workbook_1 = S.excel_1.Workbooks.Open(file);
S.worksheet_1 = S.workbook_1.Worksheets.Item(1);
N = length(S.raw_1);
all_i = 6:N;
S.ColorIndex = zeros(size(all_i));
for k = 1:numel(all_i)
i = all_i(k);
m = strcat('M',num2str(i));
S.ColorIndex_1(k) = S.worksheet_1.Range(m).Interior.ColorIndex;
S.ColorIndex_1 = transpose(S.ColorIndex_1);
end
eSheet = S.excel_1.ActiveWorkbook.Sheets;
eSheet1 = Item(eSheet,1);
eNewSheet = Add(eSheet,[],eSheet1);
S.workbook_1.Worksheets.Item(2).Name = 'Sheet_2';
end
function [] = exc_2_call (varargin)
[S.filename_xlsx_2, S.pathname_xlsx_2] = uigetfile({'*.xlsx'},'');
file = strcat(S.pathname_xlsx_2, S.filename_xlsx_2);
[S.num_2,S.txt_2,S.raw_2] = xlsread(file);
S.excel_2 = actxserver('Excel.Application');
S.excel_2.Visible = true;
S.workbook_2 = S.excel_2.Workbooks.Open(file);
S.worksheet_2 = S.workbook_2.Worksheets.Item(1);
N = length(S.raw_2);
all_i = 6:N;
S.ColorIndex_2 = zeros(size(all_i));
for k = 1:numel(all_i)
i = all_i(k);
m = strcat('M',num2str(i));
S.ColorIndex_2(k) = S.worksheet_2.Range(m).Interior.ColorIndex;
S.ColorIndex_2 = transpose(S.ColorIndex_2);
end
end
Now we're coming to the part where I can't find a solution.
function [] = df_call (varargin)
S.ID_1 = S.raw_1(6:end,12);
S.ID_2 = S.raw_2(6:end,12);
S.ID_find = ismember(S.ID_1, S.ID_2);
S.ID_find = double(S.ID_find);
[ID_row_zeros] = find(S.ID_find == 0);
ID_row_zeros_str = string(num2str(ID_row_zeros));
ID_deleted_cells = strcat('M', ID_row_zeros_str);
S.worksheet_1.Rows.Item(1).Copy;
S.workbook_1.Worksheets.Item(2).Range('A1').PasteSpecial(13);
S.worksheet_1.Rows.Item(2).Copy;
S.workbook_1.Worksheets.Item(2).Range('A2').PasteSpecial(13);
S.worksheet_1.Rows.Item(3).Copy;
S.workbook_1.Worksheets.Item(2).Range('A3').PasteSpecial(13);
S.worksheet_1.Rows.Item(4).Copy;
S.workbook_1.Worksheets.Item(2).Range('A4').PasteSpecial(13);
S.worksheet_1.Rows.Item(5).Copy;
S.workbook_1.Worksheets.Item(2).Range('A5').PasteSpecial(13);
S.worksheet_1.Rows.Item(ID_row_zeros(1,1)).Copy;
S.workbook_1.Worksheets.Item(2).Range('A6').PasteSpecial(13);
S.worksheet_1.Rows.Item(ID_row_zeros(2,1)).Copy;
S.workbook_1.Worksheets.Item(2).Range('A7').PasteSpecial(13);
S.worksheet_1.Rows.Item(ID_row_zeros(3,1)).Copy;
S.workbook_1.Worksheets.Item(2).Range('A8').PasteSpecial(13);
The thing is that I have to do it iteratively because there could be missing more than just three rows. I never know how many rows will be missing. So somehow I have to copy and paste it depending on the number of missing rows.
I hope I gave enough information to understand my problem. It's not that easy to explain such a problem. If you need some more information please let me know.
Any help/direction would be most appreciated.
Thanks in advance.
6 Comments
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_808433
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_808433
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_808654
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_808654
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_808666
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_808666
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_808962
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_808962
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_808980
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_808980
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_811692
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/510286-actxserver-copy-and-paste-iteratively#comment_811692
Sign in to comment.