matlab 如何打开excel文件,excel – Matlab xlsread打开文件并清理

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值