Code covered by the BSD License  

Highlights from
Financial Seminar Demos

from Financial Seminar Demos by Michael Weidman
Demos commonly used at The MathWorks financial modeling seminars.

excelget(FileName, SheetNo, Range)
function Data = excelget(FileName, SheetNo, Range)
% EXCELGET Load Excel data into MATLAB.
%      DATA = EXCELGET(FileName, SheetNo, Range) returns cell array DATA with
%      values from the selected range in Excel file.
%      FileName - string with file name and full path,
%                 for example 'c:\office\book1.xls'
%      SheetNo - sheet number where the data is located
%      Range - string with range selection, for example 'A1:B4'
%
%	   See also: EXCELPUT

%      Author(s): Taras Chaban 8-Jan-99
%      Copyright (c) 1995-99 by The MathWorks Ltd.

% start Excel application
ExHandle = actxserver('Excel.Application');
% make it visible
ExHandle.Visible = 0;

% open data file
invoke(ExHandle.Workbooks, 'Open', FileName);

% get collection of sheets
SheetCollect = ExHandle.ActiveWorkBook.Sheets;

% retrieve one sheet from the collection
SheetObj = get(SheetCollect, 'Item', SheetNo);

% select range of cells in Excel
RngHandle = get(SheetObj, 'Range', Range);
% get the values from the selected range
Data = RngHandle.Value;

invoke(ExHandle, 'quit');
delete(ExHandle);

return

Contact us at files@mathworks.com