Reputation: 94
I'm working with a quite big Excel file in MATLAB with the xlsread
function. I'm particularly interested in a named cell, let's say it's called FIRST_DATA. So in MATLAB I call:
[num, txt, raw] = xlsread(filename,sheet,'FIRST_DATA')
But I'm not interested in the data that this cell contains, but in the number of the row of this cell. How can I get this information?
My first guess is reading the data in the cell first, then reading the whole sheet and finally searching the resulting matrix for the cell data to find the row. But I hope for a more convenient way or one with less effort.
Thank you for your help!
Upvotes: 0
Views: 357
Reputation: 94
There is a way using ActiveX, as suggested by Adiel in the Comments. Code example:
excelapp = actxserver('Excel.Application');
workbook = excelapp.Workbooks.Open('myspreadsheet.xlsx');
worksheet = workbook.Sheets.Item('sheet_with_data');
worksheet.Activate;
row_number = worksheet.Range('FIRST_DATA').Row;
Close(workbook);
Quit(excelapp);
delete(ExcelApp);
You should be closing everything properly to to prevent potential memory leaks.
Upvotes: 1