Importing a table with unknown number of rows
14 views (last 30 days)
I have several xlsx files that contain the same columns, but different number of rows. An example xlsx file is attached. I would like to import them as tables, so I used Import Wizard to generate the attached function. The problem with the function is that it specifies the row length in opts.DataRange. However I would like to use this function on other xlxs files with the same columns, but different number of rows. How do I edit this function so it can accept any number of rows? Here's what I've tried,
dataLines = [2, Inf]; % Want to go from the 2th row to the last unknown row. Doesn't work.
opts.DataRange = "A" + dataLines(1, 1) + ":C" + dataLines(1, 2); % Columns A to C are imported from Excel file
but it crashes. I also tried
dataLines = [2, 500]; % I happen to know I always have less than 500 rows
but then my table actually has 500 rows, with the last several rows undesirably empty. I could manually delete them but I suspect there's a better way.