Filter löschen
Filter löschen

Matlab, Excel and validation of data

14 Ansichten (letzte 30 Tage)
Ortinomax am 13 Mai 2015
Beantwortet: Enes Uk am 21 Jan. 2019
Hello, I wanted to create some rule of validation on some cells in Excel documents. I used the macro-recording to see which methods, parameters are used. i get that :
Sub Macro1()
' Macro1 Macro
With Selection.Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Liste_choix!$C4:$C12"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
I tried to do the same on Matlab :
xslx = actxserver('Excel.application');
xslx.Visible = false;
myTab = xslx.Workbooks.Open(fullfile(pwd,'Liste simu Synthèse'));
sheet = xslx.Worksheets.Item(nameTab{1});
Range = sheet.get('Range', r(1), r(2));
But it won't work :
??? Error: Object returned error code: 0x800A03EC
Error in ==> trash at 27
The arguments doesn't seem to be the problem here, I teted this :
>> myRule.methods
Methods for class Interface.Microsoft_Excel_15.0_Object_Library.Validation:
Add Modify delete events invoke release set
Delete addproperty deleteproperty get loadobj saveobj
>> myRule.Add()
??? No method 'Add' with matching signature found for class 'Interface.Microsoft_Excel_15.0_Object_Library.Validation'.
I don't understand, is Add a method or not ?

Antworten (3)

Enes Uk
Enes Uk am 21 Jan. 2019
% Create an Excel object
e = actxserver('Excel.Application');
% Add a workbook
eWorkbook = e.Workbooks.Add;
e.Visible = 1;
% Make the first sheet active.
eSheets = e.ActiveWorkbook.Sheets;
eSheet1 = eSheets.get('Item',1);
% Put MATLAB data into the worksheet.
activeSheet = e.Activesheet;
eActivesheetRange = e.Activesheet.get('Range','A1:A4');
eActivesheetRange.Value = A;
% % Read the data back into MATLAB, where array B is a cell array.
% eRange = e.Activesheet.get('Range','A1:B2');
% B = eRange.Value;
% Copy data list and create data validation
% Save the workbook in a file.
% If the Excel program displays a dialog box about saving the file, select the appropriate response to continue.
% If you saved the file, then close the workbook.
eWorkbook.Saved = 1;
% Quit the Excel program and delete the server object.

chaymaa slimani
chaymaa slimani am 10 Sep. 2018
Hello ! I have the same problem as you, I wonder if you could solve it. If yes, can you share with me the solution please? Thank you in advance

Ranjith Kumar
Ranjith Kumar am 7 Jan. 2019
Hai, try the below one.
xslx.Selection.Validation.Delete; % if xslx not works, then use the sheet identifier


Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by