我在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 - 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);

只是没有结束这个过程 . 我不知道是什么导致这个功能超出这个功能(不能再介入了),并且网上没有提及它的问题 . 请帮我解释一下这种行为 . 占据我所有的记忆

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐