function data = read_excel_columns(filename,sheet,columns,firstrow,lastrow)
nrows = lastrow-firstrow+1;
ncols = length(columns);
data = zeros(nrows,ncols);
first = num2str(firstrow);
last = num2str(lastrow);
hExcel = actxserver('Excel.Application');
hWorkbook = hExcel.Workbooks.Open(filename);
hWorksheet = hWorkbook.Sheets.Item(sheet);
for i = 1:ncols
col = col2str(columns(i));
Range = [col,first,':',col,last];
RangeObj = hWorksheet.Range(Range);
data(:,i) = cell2mat(RangeObj.value);
end
release(hWorksheet)
release(hWorkbook)
release(hExcel)
end
function colname = col2str(n)
s = '';
while n > 0
s = [s,char(mod(n-1,26)+65)];
n = floor((n-1)/26);
end
colname = deblank(fliplr(s));
end
Best Answer
It's ok i found a way to do it!! (it was quite simple actually but i am totally new in programming)!