Can not get sort method to work through MS Excel COM object
Mostrar comentarios más antiguos
h_excel = actxserver('Excel.Application');
disp('Connected to MS Excel')
h_excel.Visible = 1; % show what's happening
DbPath='Z:\2ndGen\Fpa_Test\SBIRS_ST_SFP\Database\Excel_db.xlsm';
h_db = invoke(h_excel.workbooks, 'Open', DbPath);
h_DbSheet=get(h_db,'Worksheets',DbSheet);
invoke(h_DbSheet, 'Select');
h_Row4 = get(h_DbSheet, 'Rows', 4);
invoke(h_Row4, 'Select');
invoke(h_Row4, 'Insert');
Nfields=length(DbRecord);
for i=1:Nfields
h_ActiveCell = get(h_DbSheet, 'Cells', 4, i);
invoke(h_ActiveCell, 'Select');
set(h_ActiveCell, 'Value', DbRecord{i});
end
h_DbRange=get(h_DbSheet,'Range',DbSheet);
invoke(h_DbRange,'Select');
invoke(h_DbRange,'Sort','Key1:=Range("A3"),Order1:=xlAscending');
% method 1 SortStr='Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("H3"), Order2:=xlAscending, Key3:=Range("I3"), Order3:=xlAscending, Header:= xlGuess'; invoke(h_DbRange,'Sort',SortStr);
% method 2
Key1='Key1:=Range("A3")';
Order1='Order1:=xlAscending';
invoke(h_DbRange,'Sort',Key1,Order1);
Respuestas (1)
Joe
el 20 de Jun. de 2013
1 comentario
Gaurav Sinha
el 11 de Mzo. de 2015
Hey, I have a similar issue, when i run invoke I get an error message saying - "Invoke Error, Dispatch Exception; Description: The text you entered is not a valid reference or defined name"
I just want to sort a column range of an excel object
Categorías
Más información sobre Data Import from MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!