首页 > 系统服务 > 详细

Matlab使用xlsread, xlswrite函数导致excel进程无法终止的问题

时间:2015-12-03 11:33:34      阅读:698      评论:0      收藏:0      [点我收藏+]

系统版本:Win7 64位

Matlab版本:R2015b

问题描述:使用excel的操作函数,比如xlsread,xlswrite,导致excel进程无法终止,任务管理器中仍残留excel进程,打开excel文档,修改后不提示保存。

技术分享

参考:http://www.mathworks.com/matlabcentral/answers/98261-why-do-some-excel-processes-fail-to-terminate-after-using-xlsread-xlswrite-or-xlsfinfo-in-matlab

进程显示automation -Embedding,应该是某个应用占用了这个进行,然后我并没有找到是哪个应用。

解决方法:

之前的老版本Matlab R2012a并没有出现此问题,问题是在R2015b版本中的%Program Files%MATLAB\R2015b\toolbox\matlab\iofun\+matlab\+io\+internal\getExcelInstance.m文件,代码:

 1 function app = getExcelInstance
 2 %   Copyright 2015 The MathWorks, Inc.
 3 
 4      persistent excelApplication;
 5     if isempty(excelApplication) || ~isactive || excelApplication.Visible
 6         % If Excel is not available, this will throw an exception.  If
 7         % Excel has been made visible, we assume the user opened the
 8         % worksheet outside MATLAB using the same Excel process, and so we
 9         % should start a new process.
10         excelApplication = actxserver(Excel.Application);
11     end
12     app = excelApplication;
13     
14     function tf = isactive
15         % Try accessing a readonly property of the COM server to see if it is
16         % active.
17         try
18             get(excelApplication, Version);
19             tf = true;
20         catch
21             excelApplication.delete;
22             excelApplication = [];
23             tf = false;
24         end
25     end
26 end

第四行的关键词persistent,如果直接换成excelApplication=[],则不会出现进程残留的情况;

这个文件应该是R2015b版本中加上去的,之前的版本excel操作函数是直接调用actxserver函数,也没有出现此问题;

后续打算卸载R2015b版本,换成R2015a版本试试;

MATLAB各版本的下载地址(可能需要梯子):http://www.eng.utah.edu/downloads/matlab/

Matlab使用xlsread, xlswrite函数导致excel进程无法终止的问题

原文:http://www.cnblogs.com/jmpep/p/5015343.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!