Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

File contains unexpected record length. Try saving as Excel 98.

1,989 views
Skip to first unread message

Ryan

unread,
Jul 11, 2013, 10:58:11 AM7/11/13
to
So I have an .m file that reads a number of Excel data files. I have been using this .m file for several months without any errors whatsoever. However, I started using it today (without any changes having been made to the .m file, the Excel files, my version of Matlab, or anything), and now it starts giving me the following error:

xlsread('targets.xls')
??? Error using ==> xlsread at 211
File contains unexpected record length. Try saving as Excel 98.

I have searched around the Internet and other people have had this problem; however, other people have had it with very large Excel files.

The problem is my Excel file is NOT that large. It is 120 rows and 26 columns. That's a fairly small file.

I have tried everything, from copying and pasting the values into new spreadsheets, deleting empty rows and columns, etc. But nothing works.

Does anybody have any idea what the problem is here? I just noticed that if I delete 1 column, it starts reading the datafile properly. But 120x25 can't be the size limit, because I have been successfully using this program (on this datafile and LARGER ones - just a week ago this .m file used xlsread on an Excel file that was 2211x30 without any problems) for months!

So why, all of a sudden, is MATLAB refusing to read any Excel files?

Steven_Lord

unread,
Jul 11, 2013, 11:38:32 AM7/11/13
to


"Ryan " <simm...@lafayette.edu> wrote in message
news:krmh63$qj4$1...@newscl01ah.mathworks.com...
You asserted that no change has been made to MATLAB, your MATLAB program
files, or the Excel files. Based on your description I question the third of
those assertions. How are those Excel data files generated? When you open
the file in Excel, does it appear as you expect it to appear? Does one of
the cells contain an extremely long string?

I scanned through XLSREAD in several older releases. Are you using release
R2008a (or possibly earlier) on a non-Windows machine or a Windows machine
without Microsoft Excel installed? That's the newest version of XLSREAD that
has the possibility of throwing this error on line 211. [Newer versions of
XLSREAD have a blank or comment line on line 211 or have code that wouldn't
throw this error on that line.]

If so, that will have to read the Excel file in "basic mode" which as the
name implies isn't as advanced as being able to actually connect to Excel
and get it to do the reading.

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Ryan

unread,
Jul 12, 2013, 11:52:06 AM7/12/13
to
> You asserted that no change has been made to MATLAB, your MATLAB program
> files, or the Excel files. Based on your description I question the third of
> those assertions. How are those Excel data files generated? When you open
> the file in Excel, does it appear as you expect it to appear? Does one of
> the cells contain an extremely long string?

The Excel files appear exactly as I expect them to. There are no errors in them. They were generated by hand, and I have remade and deleted them to make sure there weren't weird formatting issues. There aren't. I can upload one of the Excel files if you want to look at it. But I can assure you there is no problem with them. I spent most of yesterday verifying this.



> I scanned through XLSREAD in several older releases. Are you using release
> R2008a (or possibly earlier) on a non-Windows machine or a Windows machine
> without Microsoft Excel installed? That's the newest version of XLSREAD that
> has the possibility of throwing this error on line 211. [Newer versions of
> XLSREAD have a blank or comment line on line 211 or have code that wouldn't
> throw this error on that line.]
>
> If so, that will have to read the Excel file in "basic mode" which as the
> name implies isn't as advanced as being able to actually connect to Excel
> and get it to do the reading.
>

Oops, I should have mentioned this in the OP. I am running R2008a on a Mac.

I realize the limitations of using XLS read on a Mac. However, these same exact Excel files and same exact code were operating completely fine a week ago. To my knowledge, no change has been made to the computer, and this error only started occurring yesterday.

What is the size limit of "basic mode"? Is 120 x 30 really too big? If so, why was it working so well previously?

Steven_Lord

unread,
Jul 15, 2013, 11:36:40 AM7/15/13
to


"Ryan " <simm...@lafayette.edu> wrote in message
news:krp8n6$104$1...@newscl01ah.mathworks.com...
I don't know of any size limit for "basic mode", but I'd be wary about using
it for any file whose size exceeds the limitations of Excel itself, and 120
x 30 doesn't come close to that.

I recommend that you send the Excel file that used to work but doesn't work
now as well as the code you use to import it to Technical Support for
investigation and/or put them on some file hosting site and post a link to
it here. I will likely not have an opportunity to review it, but another
reader of the group might be able to determine what's going on.

Paul

unread,
Sep 20, 2013, 12:07:06 PM9/20/13
to
Hey, I had this same problem of unexpected record length with an xls file of decent size too using Matlab2011 on a mac. It occured for me that the problem came from the first row where were my string text and more specifically from the special characters like ° or ( or ). After replacing them by letters only, the problem was solved, I hope this can help.

Simon Woodward

unread,
Sep 23, 2014, 6:00:12 PM9/23/14
to
"Ryan" wrote in message <krmh63$qj4$1...@newscl01ah.mathworks.com>...
I'm having a similar problem in Windows 7. Matlab 20009b, Excel 2010 Professional. xlsread suddenly stopped working (couldn't start the COM server) and using the xlsread 'basic' mode, getting the same error as you. When the data file was in an older version of Excel, I got a different problem, some of the text was read in as NaNs.

dpb

unread,
Sep 23, 2014, 6:03:40 PM9/23/14
to
On 09/23/2014 5:00 PM, Simon Woodward wrote:
> "Ryan" wrote in message <krmh63$qj4$1...@newscl01ah.mathworks.com>...
...

>> So why, all of a sudden, is MATLAB refusing to read any Excel files?
>
> I'm having a similar problem in Windows 7. Matlab 20009b, Excel 2010
> Professional. xlsread suddenly stopped working (couldn't start the COM
> server) and using the xlsread 'basic' mode, getting the same error as
> you. When the data file was in an older version of Excel, I got a
> different problem, some of the text was read in as NaNs.

More than likely an update has scrogged a dll...

Try to roll back any recent updates or see if there are any more recent
that might undo the damage.

--

Ricardo A. Baila

unread,
Jul 26, 2016, 5:52:08 AM7/26/16
to
"Ryan" wrote in message <krmh63$qj4$1...@newscl01ah.mathworks.com>...
Since I just had the same problem, I'll ignore the age of this topic.

Conditions:
Mac OS X El Capitan v10.11.5
Matlab version 8.6.0.267246 (2015b)
Excel for Mac 15.17 (151206)

Description:
Imported the excel file (xls) from an "hand-written" prn file (space separated values), readable by MatLab (the purpose of this import was exactly to make the original file more user friendly, thus directly an Excel file).

Problem:
Firstly, while using xlsread
" Error using xlsread (line 251)
File contains unexpected record length. Try saving as Excel 98. "

Following the tip from an user above, removed all non text characters from the non numerical cells.

After this xlsread worked, but all non integers were read as NaN.

Quickly understood that Excel is using a different decimal operator from MatLab (the "," instead of the "."). Replaced all and problem solved.

Hopes this summarizes the solution for anyone who faces the same problem.
0 new messages