我在1.4 MB excel文件上使用xlsread . 运行我的m代码几次后,我开始注意到一些奇怪的行为 .
-
我无法使用双击打开excel文件(只能使用matlab)
-
2个大型(30Mb)EXCEL.EXE * 32个文件打开,每个m代码运行前清除(我调用该函数2次)
我像matlab一样没有清理它的文件句柄 . 我使用拐角到拐角读取的更新代码使用以下两行读取数据
prs = xlsread(file, 'data2','A2:C550');
elm = xlsread(file, 'element','A2:C65536');
调用两个函数后,任务管理器显示两个大的EXCEL.EXE * 32文件 . 我试过了
clear
clear all
close all
fclose('all')
fclose(0); fclose(1); fclose(2)
我关闭了matlab,它们仍然是开放的 .
在尝试重新启动后没有结果,进行了一些窥探 .
xlsread使用excel来填充看起来像excel的服务器
Excel = actxserver('excel.application');
清理看起来应该发生在这里
cleanUp = onCleanup(@()xlsCleanup(Excel, file));
[numericData, textData, rawData, customOutput] = xlsreadCOM(file, sheet, range, Excel, customFun);
接下来是
clear cleanUp;
后来在该计划中 . 研究表明,这应该运行一个名为xlsCleanup的清理函数 . 将文件复制到此处以供参考 .
function xlsCleanup(Excel, filePath)
try %#ok<TRYNC> - Suppress any exception
%Turn off dialog boxes as we close the file and quit Excel.
Excel.DisplayAlerts = 0;
%Explicitly close the file just in case. The Excel API expects
%just the filename and not the path. This is safe because Excel
%also does not allow opening two files with the same name in
%different folders at the same time.
[~, n, e] = fileparts(filePath);
fileName = [n e];
Excel.Workbooks.Item(fileName).Close(false);
end
Excel.Quit;
end
首先,它很烦人,它在没有警报的情况下捕获异常 . 我查了一下,但代码没有抛出异常 . 看来就行了
Excel.Workbooks.Item(fileName).Close(false);
只是没有结束这个过程 . 我不知道是什么导致这个功能超出这个功能(不能再介入了),并且网上没有提及它的问题 . 请帮我解释一下这种行为 . 占据我所有的记忆
3 回答
范围参数也适用于角落 . 从xlsread的文档:
这意味着你可以这样做:
这适合我 .
仍然没有matlab问题的解决方案 . 这就是我用来关闭运行我的文件几次后仍然打开的百万个进程 .
在Cygwin: