How can I import filtered Data from Excel into Matlab
7 views (last 30 days)
Show older comments
Hello everyone, I´m trying to filter Data in an Excel Sheet via COM-Server and then importing it into Matlab. My Test-Sheet looks like this:
[Active] [x] [y]
0 1 1
1 2 4
1 3 9
1 4 16
0 5 25
0 6 36
1 7 49
0 8 64
0 9 81
1 10 100
0 11 121
1 12 144
1 13 169
1 14 196
And my Matlab-Code so far:
exl = actxserver('excel.application'); % create COM-Server
str = strcat(pwd,'\TestData.xlsx'); % Path of the Excel-File
exlWkbk = exl.Workbooks;
exlFile = exlWkbk.Open(str);
robj = exlFile.ActiveSheet.Columns.End(4); % Find the end of the column
numrows = robj.row; % And determine what row it is
dat_range = ['A1:C' num2str(numrows)]; % Read to the last row
exlFilter = exlFile.ActiveSheet.Range(dat_range).AutoFilter(1,'1') % filters the data to only show rows with the value 1 in the first column
exl.Visible = 1; % show Excel Sheet
Cells = exlFile.ActiveSheet.Range(dat_range).SpecialCells('xlCellTypeVisible').Value % import filtered data
The connection to the Sheet and the application of the filter works fine, however the variable 'Cells' only contains the first line of the Sheet (Cells = [Active][x][y]). But when I set the Sheet on visible, the filter is applied correctly and exlFile.ActiveSheet.Range(dat_range).SpecialCells('xlCellTypeVisible').Count returns the correct number of 27 cells...
Has anyone an idea how i can read the filtered data from the excel sheet?
0 Comments
Answers (1)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!