Import data from xlsx file - how to import without a specified range

2 vues (au cours des 30 derniers jours)
Jenny
Jenny le 12 Fév 2016
Commenté : Fangjun Jiang le 12 Fév 2016
Hi,
I am importing data from an *.xlsx file using xlsread.
The range is specified (in my code as 'A3:M4508'). How do I import the file without specifying the range in this way?
The range varies (depending on the data file length) so I like to be able to find the end of the data file (the length) automatically?
The file format is always the same. There are two header rows and the data starts on row A3.
It columns are from A to M.
Thanks, Jenny
[filename,pathname] = uigetfile({'*.*';'*.txt';'*.csv';'*.xls'},'Select the data file file to import');
[~, ~, raw, dates] = xlsread(fullfile(pathname,filename),'Data','A3:M4508','',@convertSpreadsheetExcelDates);

Réponses (1)

Fangjun Jiang
Fangjun Jiang le 12 Fév 2016
If it is always to process all the data, would this work?
[~, ~, raw] = xlsread(fullfile(pathname,filename),'Data');
dates=convertSpreadsheetExcelDat(raw);
  2 commentaires
Jenny
Jenny le 12 Fév 2016
Hi.
That does not work. I get the error:
Attempt to reference field of non-structure array.
Error in convertSpreadsheetExcelDates (line 26) rawDataWithDatesAsString = DataRange.Value;
Error in ReadCurrentData (line 133) dates=convertSpreadsheetExcelDates(raw);
Any other suggestions ?
Fangjun Jiang
Fangjun Jiang le 12 Fév 2016
xlsread(File,Sheet) allows not to provide the Range input argument. But the code wants to execute the convertSpreadsheetExcelDates() at the same time and it seems that the function requires the range input arguments.
I would suggest to separate the read of the Excel file and the processing of the data. Once the data is read from the Excel file, it is easy to get the size information of the data. You might have to re-write the convertSpreadsheetExcelDates() function. Run it separately after the data is read. Don't make it run through the call of xlsread().

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by