xlsread only works once per matlab session
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Fangjun Jiang
am 1 Aug. 2011
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?
Antworten (7)
Edward Umpfenbach
am 3 Mär. 2012
I ended up just saving my workbook as a csv and using csvread. Works fine. Thanks, though.
0 Kommentare
Charles
am 25 Aug. 2015
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 Kommentare
Fangjun Jiang
am 29 Jul. 2011
Maybe it is due to memory problem. Can you try clear all and then run xlsread() again?
Edward Umpfenbach
am 28 Feb. 2012
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 Kommentare
Marc
am 23 Jul. 2013
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
am 5 Feb. 2013
Bearbeitet: Walter Roberson
am 6 Feb. 2013
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 Kommentare
Charles
am 3 Aug. 2015
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 Kommentare
Siehe auch
Kategorien
Mehr zu Data Export to MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!