Matlab number of lines in excel file

is there a matlab command to get the number of lines written in an excel file? Firstly, I fill in the first line. and then I want to add some more lines to the excel file. so this is my excel file: enter image description here

I tried:

e = actxserver ('Excel.Application');
filename = fullfile(pwd,'example2.xlsx');
ewb = e.Workbooks.Open(filename);
esh = ewb.ActiveSheet;

sheetObj = e.Worksheets.get('Item', 'Sheet1');
num_rows = sheetObj.Range('A1').End('xlDown').Row

But num_rows = 1048576, not 1. please help, thanks!

+5
source share
2 answers

If the file is empty or contains data in only one line, it will .End('xlDown').Row;move to the very bottom of the sheet ( 1048576- this is the number of lines in the Excel 2007+ sheet).

Check if the cell is A2first empty, and return 0if there is one.

Or use the Upbottom of the sheet

num_rows = sheetObj.Cells(sheetObj.Rows.Count, 1).End('xlUp').Row 

. Matlab,

+4

MATLAB xlsread . :

[numbers strings misc] = xlsread('myfile.xlsx');

size strings misc, :

[rows columns] = size(strings);

, rows = 1, columns = 10 (, "A" ).

+1

All Articles