【发布时间】:2012-04-09 19:55:09
【问题描述】:
我需要使用 ActiveX 从 Matlab 中打开一个现有的 excel 工作簿。 xlsread 不可行,因为太慢了。从这个论坛获得帮助后(谢谢!)我知道要从 matlab 中创建一个新的 excel 工作簿并用输出填充它,你可以这样做:
%# Create and NAME the output file name
wbk=1;fName = fullfile(pwd, 'ALLSDtemp2');
%# create Excel COM Server
Excel = actxserver('Excel.Application');
Excel.Visible = true;
%# delete existing file
if exist(fName, 'file'), delete(fName); end
%# create new XLS file
wb = Excel.Workbooks.Add();
wsheet=1;
(...calculations...)
% Write output to excel file
Mat=[calculation_output];
% Select work book
wb.Sheets.Item(wsheet).Activate();
% Get Worksheets object
ws = wb.Sheets;
%# insert matrix in sheet
Excel.Range(cellRange).Select();
Excel.Selection.Value = num2cell(Mat);
但我不知道如何使用已经存在的 Excel 工作簿来执行此操作。前几天我的努力导致我的电脑出现“严重错误”。所以我真的可以使用一些指导。
谢谢
【问题讨论】:
-
对于“太慢”的问题,这个其他答案有你需要的解决方案:stackoverflow.com/a/6784516/97160