xlsread only works once per matlab session
조회 수: 1 (최근 30일)
이전 댓글 표시
xlsread will work once and then it returns:
Error: Object returned error code: 0x800AC472
Error in ==> xlsread at 236
Excel.DisplayAlerts = 0
If I close Matlab and reopen it works one time again...
댓글 수: 1
Fangjun Jiang
2011년 8월 1일
open xlsread.m file, put a break point on line 236 or before, step through to see if you can find anything useful. What is the OS, Office and MATLAB version of yours?
답변 (7개)
Edward Umpfenbach
2012년 3월 3일
I ended up just saving my workbook as a csv and using csvread. Works fine. Thanks, though.
댓글 수: 0
Charles
2015년 8월 25일
Mathworks followed up with some suggestions, and through experimentation I came up with a solution that appears to work. The bottom line is getting MatLab to disable the PI addins before performing any xlsread (or I am now using X Collection), and then re-enable when the files are closed. In order to handle less-than-graceful endings, I use Cleanup to re-enable.
In my main code I use:
DisableAddins(false)
cleanUp = onCleanup(@()DisableAddins(true));
Then the DisableAddins Routine is:
function DisableAddins(newflag, appExcel)
%%Run this before xlsread
try
disp('attempting to adjust excel addins')
if nargin==1
appExcel = actxserver('Excel.Application');
end
numAddins = appExcel.AddIns.Count;
for ii = 1:numAddins
addName = appExcel.AddIns.Item(ii).Name;
if strcmpi(addName,'pipc32.xll')
hAddin = appExcel.AddIns.Item(ii);
hAddin.Installed = newflag;
end
end
numCOMAddins = appExcel.COMAddIns.Count;
for ii = 1:numCOMAddins
addName = appExcel.COMAddIns.Item(ii).ProgId;
if strcmpi(addName,'PI DataLink')
hAddin = appExcel.COMAddIns.Item(ii);
hAddin.Connect = newflag;
end
end
catch error1
if exist('appExcel','var') && nargin==1
%Close out excel if it was not open on entry
appExcel.Quit;
clear appExcel
end
rethrow(error1)
end
if nargin==1
appExcel.Quit;
clear appExcel
end
If you are manually opening the COM connection instead of using xlsread, you can pass in the handle to the COM connection and it will use that connection.
This seems to have solved our problem with PI.
Chuck
댓글 수: 0
Fangjun Jiang
2011년 7월 29일
Maybe it is due to memory problem. Can you try clear all and then run xlsread() again?
Edward Umpfenbach
2012년 2월 28일
I am also running into this exact same problem. Matlab 2010a, excel 2010.
I write:
price_per_mile = xlsread('C:\Users\Ed\Documents\MATLAB\Data_Input.xls','Inputs','B1:B1');
carbon_per_mile = xlsread('C:\Users\Ed\Documents\MATLAB\Data_Input.xls','Inputs','B2:B2');
The excel file is pretty large but I am only trying to test this right now and import a single cell, then a second cell. Crashes everytime. Any ideas?
댓글 수: 3
Marc
2013년 7월 23일
I agree with Friedrich. When my company updated to Office 2007, I had a PI add on from OSIsoft that was causing my code that called an excel file multiple times, accessing multiple sheets, trouble. This was with 2011b and office 2007. Disabling the add-on got me working again.
From what I could tell, when Matlab "opened" the excel file, the PI add on was trying to initialize to the historian's server and not allowing Matlab to re-access the file.
I also disabled Office 2007 "getting started" add ons because I found xlsread ran faster once those were disabled.
Of course, you never know since my company's IT dept was always pushing "fixes" onto our computers which seemed to constantly screw up our in house software.
Don
2013년 2월 5일
편집: Walter Roberson
2013년 2월 6일
xlsWRITE will work once and then it returns:
Error: Object returned error code: 0x800AC472
Error using xlswrite (line 220)
Error: Object returned error code: 0x800AC472
If I close Matlab and reopen it works one time again...
How can I fix this for use in a script? If I enter the commands in Command window it works OK
Here's the script code:
[p,n,e]=fileparts(filename);
newFileName = fullfile(filepath, [n,'Ratio']);
xlswrite(newFileName,RatioResults);
댓글 수: 0
Charles
2015년 8월 3일
I am running into this with MatLab 2015a. Runs through first time (four different xlsread statements, different files). On second run, it fails, not always on the first xlsread, but it will fail. It fails trying to close the com link (quit). Disable PI add-in, all is well. However, customer uses PI (and the data in the spreadsheet comes from PI). MatLab tech support says not their problem, it is third party add-in. However, the add-in does not fail, MatLab fails. Tech support gave me some Excel commands to make a macro to disable the add-in. However, the macro only disables the Excel Addin, but PI uses two, one excel and one COM.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Export to MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!