some matlab to excel commands



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);

.



Relevant Pages

  • Re: Missing commands in menus of Excel 2004
    ... toolbar all the commands from Cut to Paste Special and Delete are ... Yet the cell immediately ... below the list accepted the change in format and played its part in a ... bring home spreadsheets written in Excel 2003. ...
    (microsoft.public.mac.office.excel)
  • Re: Pasting numbers and formulas without pasting format.
    ... point to the Fill Handle at the bottom right of the cell. ... If you're copying and pasting values, you could add the Paste Values ... Scroll down the list of commands to find Paste Values ... Excel FAQ, Tips & Book List ...
    (microsoft.public.excel.misc)
  • some matlab to excel commands
    ... Here are some commands that are hard to find on the group, ... How to write to excel using Matlab. ... to write data to active sheet, ... To write a formula to the active sheet, cell A1: ...
    (comp.soft-sys.matlab)
  • Re: Find value in a column and insert rows above
    ... It is running on the active sheet, it goes once and inserts a cell rather ... "Dee Sperling" wrote: ... I'm using Excel 2003, is that the cause? ...
    (microsoft.public.excel.programming)
  • Missing commands in menus of Excel 2004
    ... For a while now some commands in Excel 2004 haven't been available ... Yet the cell immediately ... below the list accepted the change in format and played its part in a ...
    (microsoft.public.mac.office.excel)