some matlab to excel commands
- From: "Marc" <shaak1979@xxxxxxxxxxx>
- Date: 25 Jul 2005 01:02:41 -0700
Here are some commands that are hard to find on the group, as well as
some hints.
Greets and have fun!
How to write to excel using Matlab.
In Excel, one can use com-servers to make a connection to excel, and
execute commands, read and write data to/from.
Commands can be retrieved by taking a look at the visual basic editor
(open by pressing [ALT + F11] ). In VB editor, open the object browser
by pressing [F2]. By changing <all libraries> to EXCEL, one can view
all the commands for EXCEL. Some of these commands can be used via a
COM- server. Playing around with the commands is usually the best
method to find things out, but is a tedious process. The following
commands seem to work:
To start, a com-server has to be opened:
Excel = actxserver('Excel.Application');
To make Excel visible:
Excel.Visible = 1;
To make Excel invisible again:
Excel.Visible = 0;
1 stands for the logical value TRUE, 0 for FALSE. From now on only on
direction will be shown to reduce text length.
To suppress warnings:
Excel.DisplayAlerts = 0;
To add a workbook:
Excel.Workbook.Add;
To open a workbook:
invoke(Excel.Workbooks,'Open','filename');
To create a handle to the sheets(needed in communicating more easily)
Sheets = Excel.ActiveWorkBook.Sheets;
Get number of sheets in workbook:
nr_of_sheets = Excel.ActiveWorkbook.Sheets.count;
to make a target sheet(in this case the first sheet) active(for writing
to, deleting); create a handle to the sheet:
cursheet = get(Sheets, 'Item', 1);
to delete the active sheet:
invoke(cursheet, 'Delete');
to rename the sheet:
cursheet.Name='NewName';
to write data to active sheet, cell A1:
CurSheet.Range(['A1']).Value = ['value'];
To write data range to active sheet, cel A1:B2:
CurSheet.Range(['A1:B2']).Value = [{['cell A1']} [{['cell
B1']} ; {['cell A2']} {['cell B2']}];
A range has to be put in an array of cells!
To write a formula to the active sheet, cell A1:
CurSheet.Range(['A1']).formula = ['formula'];
To make the text in cell A1 bold:
CurSheet.Range(['A1']).Font.Bold = 1;
In the end, all of the handles have to be released:
release(handle);
and the COM server has to be closed:
Quit(Excel);
.
- Follow-Ups:
- Re: some matlab to excel commands
- From: Jérôme
- Re: some matlab to excel commands
- Prev by Date: resampling problem
- Next by Date: some matlab to excel commands
- Previous by thread: resampling problem
- Next by thread: Re: some matlab to excel commands
- Index(es):
Relevant Pages
|