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

2 ビュー (過去 30 日間)
Jenny
Jenny 2016 年 2 月 12 日
コメント済み: Fangjun Jiang 2016 年 2 月 12 日
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);

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2016 年 2 月 12 日
If it is always to process all the data, would this work?
[~, ~, raw] = xlsread(fullfile(pathname,filename),'Data');
dates=convertSpreadsheetExcelDat(raw);
  2 件のコメント
Jenny
Jenny 2016 年 2 月 12 日
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 2016 年 2 月 12 日
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().

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by