xlsread error

35 visualizaciones (últimos 30 días)
Sarah
Sarah el 12 de Abr. de 2012
Comentada: Image Analyst el 6 de Sept. de 2020
Hey guys,
I can't seem to figure out why I get this error while trying to run some code. It is related to the xlsread function that I am using. Here is the code that I have:
[T5.Sig, T5.TStr] = xlsread('chambertest5.xlsx',1,'C5:K608469');
Here is the error that I get:
Source: Microsoft Office Excel
Description: Open method of Workbooks class failed
Help File: C:\Program Files (x86)\Microsoft Office\Office12\1033\XLMAIN11.CHM
Help Context ID: 0
Error in ==> xlsread at 250
ExcelWorkbook = Excel.workbooks.Open(file,0,true);
As you can see, I am trying to read a lot of data. Do you think that is the problem? Thanks for your time.
  2 comentarios
Image Processing
Image Processing el 27 de Sept. de 2016
What is the size of your file ?
Dries
Dries el 18 de Jul. de 2017
217 kb

Iniciar sesión para comentar.

Respuestas (8)

Greydon Gilmore
Greydon Gilmore el 22 de Ag. de 2017
Hi All,
Sorry for reviving an old post but I had this same issue.
I resolved it by running task manager and ending all excel running processes. I viewed the excel file I was attempting to open with Matlab just before running xlsread. Ending all processes through task manager seemed to solve the problem.
Cheers, Greydon
  3 comentarios
dinesh sah
dinesh sah el 4 de Sept. de 2020
work for me too...
Image Analyst
Image Analyst el 6 de Sept. de 2020
Greydon, I think this should have been a comment to me, rather than a "new" answer", since I already mentioned this in my answer: "are you sure the file is not already open in Excel when you try to open it via your MATLAB code? Type ctrl-shift-Esc to check for any hidden Excel processes that may be running but not visible to you." This nice shortcut key sequence works in Windows only.

Iniciar sesión para comentar.


Sarah
Sarah el 12 de Abr. de 2012
anyone?
  2 comentarios
Walter Roberson
Walter Roberson el 12 de Abr. de 2012
To determine whether the problem is in asking for too much data, temporarily change it to ask for only a little data.
I'm relatively sure you will find that the error stays even if you only ask for a little data.
Sarah
Sarah el 12 de Abr. de 2012
The error does stay even if I ask for little data. and I closed the excel file to see if that was causing a problem, and it still does.
any suggestions?

Iniciar sesión para comentar.


Eric
Eric el 12 de Abr. de 2012
I would try using the Excel COM interface directly to see where Excel is struggling. It's interesting that it seems to be failing when simply opening the worksheet. The following might let you test that.
First, close Excel. Make sure Excel is not running in the background by looking for any Excel.exe processes in Task Manager. Then...
XLS_COM = actxserver('Excel.Application');
XLS_COM.Visible = 1;%Make Excel Visible
WB_COM = XLS_COM.Workbooks.Open(filename);%Open the specified workbook - provide the full path
SheetOBJ = WB_COM.Sheets.Item(1);%Using the first worksheet
RangeOBJ = SheetOBJ.Range('C5:K608469');
data = RangeOBJ.Value;%Creates a cell array
You could also try reading data without using Workbooks.Open(). In that case, close Excel and make sure no instances of Excel are running. Then open Excel and then open your file. Make sure your workbook is the only one open. Then...
XLS_COM = actxGetRunningServer('Excel.Application');
WB_COM = XLS_COM.Workbooks.Item(1);
SheetOBJ = WB_COM.Sheets.Item(1);%Using the first worksheet
RangeOBJ = SheetOBJ.Range('C5:K608469');
data = RangeOBJ.Value;%Creates a cell array
If it really is Workbooks.Open() that's causing the problem, this second approach avoids the necessity of calling that method. You might want to test these out with smaller ranges as well.
Good luck,
Eric

Image Analyst
Image Analyst el 12 de Abr. de 2012
First of all, are you sure your worksheet actually has 608 thousand rows in it? If it does, then are you sure the file is not already open in Excel when you try to open it via your MATLAB code? Type ctrl-shift-Esc to check for any hidden Excel processes that may be running but not visible to you. If there is no instance of Excel running, then it could be a memory issue and you may have to read it in smaller chunks, or else try to delete() any temporary large arrays that are taking up memory in your function or any calling parent functions to try to free up memory.
Try this, where I check that the file exists and try to read in just a small part of the worksheet:
folder = pwd;
baseFileName = 'chambertest5.xlsx';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
else
message = sprintf('Success!\nWorkbook %s was found!', fullFileName);
uiwait(msgbox(message));
end
% If we get here, the file was found.
% Read a small chunk to test it.
% If it works, try reading the full worksheet.
[num, txt, raw] = xlsread(fullFileName ,1,'C5:K60');
  2 comentarios
Sarah
Sarah el 12 de Abr. de 2012
I tried everything you said, but i still have no success!
btw, how am i supposed to know if the file was found or not? my output is:
basefilename = chambertest5.xlsx
fullfilename = chambertest5.xlsx
Image Analyst
Image Analyst el 12 de Abr. de 2012
I edited it so that it will now tell you if it found the workbook. Of course you could have also stepped through it with the debugger. But your workbook probably does exist. I just wanted to make sure it does exist in case it was not in your current folder and was somewhere else, in which case robust code like this will alert you to the fact rather than give some error that you don't understand or think is due to another reason.
So, were you able to read in a smaller chunk of the workbook?

Iniciar sesión para comentar.


Edward Umpfenbach
Edward Umpfenbach el 12 de Abr. de 2012
I had a different error with .xlsx read. I ended up saving my file as a .csv and reading it into matlab function csvread.
Doesn't really hit on the root of your issue but it might get you around it.
  3 comentarios
Edward Umpfenbach
Edward Umpfenbach el 12 de Abr. de 2012
Agreed, but it was far easier than trying to debug the error. Saving as a csv cost me about 5 seconds. Here is the thread I was mentioning, if you are curious:
http://www.mathworks.com/matlabcentral/answers/12705-xlsread-only-works-once-per-matlab-session
Image Analyst
Image Analyst el 12 de Abr. de 2012
Well if you're just using it as a way to store data and won't ever really deal with it in Excel, then a CSV file will be much, much faster anyway, since you don't have to launch Excel and shutdown Excel every time you want to write out some data.

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 18 de Jul. de 2017

Varun Bansal
Varun Bansal el 5 de Mzo. de 2019
I solved this issue by doing --
Make a Desktop folder in C:\Windows\SysWOW64\config\systemprofile and C:\Windows\System32\config\systemprofile
This will only work, if you are using a SYSTEM account to access excel, In my case, I am doing this excel automation on a build server.
Thanks MS Windows, generating bugs and breads for developers.

Scott Hazell
Scott Hazell el 13 de Mzo. de 2020
Editada: Scott Hazell el 13 de Mzo. de 2020
I had this same error and did the old IT crowd turn it off and on again (closed matlab and re open) and it worked.
Hope this helps.
: )

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by