Matlab如何读取Excel 表格数据

% Open Excel, add workbook, change active worksheet,
% get/put array, save, and close

% First open an Excel Server
Excel = actxserver('Excel.Application');
set(Excel, 'Visible', 1);

% Insert a new workbook
Workbooks = Excel.Workbooks;
Workbook = invoke(Workbooks, 'Add');

% Make the second sheet active
Sheets = Excel.ActiveWorkBook.Sheets;
sheet2 = get(Sheets, 'Item', 2);
invoke(sheet2, 'Activate');

% Get a handle to the active sheet
Activesheet = Excel.Activesheet;

% Put a MATLAB array into Excel
A = [1 2; 3 4];
ActivesheetRange = get(Activesheet,'Range','A1:B2');
set(ActivesheetRange, 'Value', A);

% Get back a range. It will be a cell array,
% since the cell range can
% contain different types of data.
Range = get(Activesheet, 'Range', 'A1:B2');
B = Range.value;

% Convert to a double matrix. The cell array must contain only scalars.
B = reshape([B{:}], size(B));

% Now save the workbook
invoke(Workbook, 'SaveAs', 'myfile.xls');

% To avoid saving the workbook and being prompted to do so,
% uncomment the following code.
% Workbook.Saved = 1;
% invoke(Workbook, 'Close');

% Quit Excel
invoke(Excel, 'Quit');

% End process
delete(Excel);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值