Clear Filters
Clear Filters

XLSX import for custom range with unknown end and providing name of columns from not first row

9 views (last 30 days)
I am importing .xlsx file into MatLab (file is provided) by using following command.
Input1 = readtable('OutputFile.xlsx','sheet',2);
There I am interested only in second sheet and custom range 17:end,[7,23:end]. The problem is that this file is generated automatically and I never know which will be the end range values. Is it possible to add the custom range for import? The 'Range' command provides only known end imports.
Do I have to import it normaly, then create new table with additional command?
If yes, then I have another problem. As soon as I import the custom range, I want first row to be considered as name of columns. There is no such command as 'ReadRowName', true as in readtable.
I tried something like that but it is not working
WorkData = Input1(17:end,[7,23:end], 'ReadRowNames', 'true');

Answers (1)

Mohith Kulkarni
Mohith Kulkarni on 25 Aug 2020
Hi, I can see that you are unable to determine the range of the data as it is varying. You would like to read the rows and columns of your choice. You can use detectImportOptions to modify the import options. Here, 'detectImportOptions' returns an spreadsheetImportOptions object which contains all the import options, including the 'VariableNames' input option. Refer to the readtable function for more information. Refer to the following code.
opts = detectImportOptions('OutputFile.xlsx','sheet',2);
opts.DataRange = [7 Inf]; %rows;
cols = length(opts.VariableNames); %finding number of columns;
opts.SelectedVariableNames = [7, 23:cols];
Input1 = readtable('OutputFile.xlsx',opts);




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!