Reading Excel files on a Mac
Show older comments
Trying to read some data from Excel files into Matlab, but my files seem to be causing quite a few problems. I'm working on a Mac (Matlab R2010a, Excel 2004 for Mac), so I attempt to read via:
[num,txt,raw] = xlsread(filename, 1, '', 'basic');
35 of the 41 files produce the following error:
??? Error using ==> xlsread at 234
File could not be read by biffparse. Invalid record ID.
while the remaining 6 files instead error with:
??? Error using ==> xlsread at 234
File does not contain recognized Excel data. Try saving as Excel 98.
The first error arises from a call to biffparse on line 470 of xlsread (trying to read sheet names), while the latter comes from a later call to biffparse on line 485 of xlsread (trying to read data from first sheet). Unfortunately, biffparse itself is a mex file, so I can't look further into exectly what it's stumbling over.
Each of my files include 30-35 worksheets, each holding a formatted table (mix and text and numbers). All are Excel 5.0/95 workbooks. Unfortunately I can't take Matlab's advice and save in '98 format, since this is not an export option in my version of Excel. Because of the high number of sheets, I'd really like to avoid converting all the files to .csv files. Anyone know what might be causing xlsread to stumble here? Or know of a tool that more reliably imports .xls files to Matlab sans COM server?
Answers (3)
Kelly Kearney
on 1 Sep 2011
Fangjun Jiang
on 31 Aug 2011
0 votes
Hah, found this! Hope that is the cause of the problem.
[NUMERIC,TXT,RAW]=XLSREAD(FILE,SHEET,RANGE,'basic') reads an XLS file as above, using basic input mode. This is the mode used on UNIX platforms as well as on Windows when Excel is not available as a COM server. In this mode, XLSREAD does not use Excel as a COM server, which limits import ability. Without Excel as a COM server, RANGE will be ignored and, consequently, the whole active range of a sheet will be imported. Also, in basic mode, SHEET is case-sensitive and must be a string. And this is still required as late as R2011a. http://www.mathworks.com/help/techdoc/ref/xlsread.html
One cheap shot is to just try xlsread(filename) to see if it goes through.
In your Excel 2004 for Mac, can you do "Save As..." then in the dropdown list for "save as type", choose the version for '98 format? That is how I do conversions.
4 Comments
Kelly Kearney
on 31 Aug 2011
Fangjun Jiang
on 31 Aug 2011
No more clues. Your suspicion is probably right. It's the old Excel format. Do you have to use 'basic' option on Mac? What you got if you just run xlsread(filename)?
Kelly Kearney
on 31 Aug 2011
Fangjun Jiang
on 31 Aug 2011
It sounds like a dead end. You have Excel on Mac so it doesn't have the COM server. I think you best shot is to ask someone to convert the Excel files for you.
Jai Davies-Campbell
on 10 Nov 2017
Edited: Jai Davies-Campbell
on 10 Nov 2017
0 votes
I use TextWrangler... just copy and paste into TW and save it as a .txt file and then load that into Matlab. Seems to work.
Example
Peel_Angle=load(['Aramoana_Cam1_2013_Peel_Angles.txt']);
Name=Peel_Angle(:,1); PA1=Peel_Angle(:,2); PA2=Peel_Angle(:,3);
change to suit
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!