Macro command Write

<< Click to Display Table of Contents >>

Navigation:  Macros > Macro commands and parameters > Macro reporting commands > Macro write to Excel >

Macro command Write

Purpose:

Write a value in a cel of a worksheet.

 

General notation:

Write ( FileIndex, sheet , row  , column , value )

 

FileIndex 0: standaard output to Excel on your computer.

FileIndex 1..9: index pointing to the opened spreadsheet file.

Using the Open command a spreadsheet file is assigned to a FileIndex for Read and Write commands. The FileIndex is an integer number between 1 and 9. This means that a maximum of nine spreadsheet files can be opened simultaneously. If more files have to be read, firstly other files have to be closed using the  Close command.

Writing to FileIndex 0 creates a new runtime Excel-file. It opens automatically and remains open in Excel after execution of the macro. The results has to be saved manually.

A new Excel file can also be created with FileIndex 1 to 9 by using Create.

 

The format can be specified together with the value.

 

In the case that the value is an object, the commands writes to the worksheet cell: the object type, directly followed by the object name.

 

The worksheet cell can be accessed by its row and colum number. The normal Excel notation (identification of a cell by means of a combination of letters and numbers) is not possible because the macro language works on a numeric basis.

 

Example:

Execute an n-1 contingency analysis for all branches in selection ‘MV-network’ and present the voltage of node ‘MyNode’:

 Set( year, 2006 )

 Write ( 0 , 1 , 1 , 1 , 'Results N-1 contingency analysis year: ' )

 Write ( 0 , 1 , 1 , 2 , year )

 Set( row, 3)

 Write ( 0 , 1 , row , 1 , 'Failing branch:' )

 Write ( 0 , 1 , row , 2 , 'Voltage (p.u.):' )

 ForSelection( Branch( 'MV-network' ), failingbranch )

         Add( row, 1 )

         Write( 0 , 1, row, 1, failingbranch )

         Set( failingbranch.FirstSwitch, open )

         Loadflow( 0, , true )

         Write( 0 , 1, row, 2, Node( 'MyNode' ).Upu)

         Set( failingbranch.FirstSwitch, closed )

 End

 

This example yields the following Excel worksheet:

 

Results N-1 contingency analysis year:

2006



Failing branch:

Voltage (p.u.):

Link

1.0199

Cable MSStat - Stat1 circuit 1

0.9798

Cable MSStat - Stat1 circuit 2

0.9798

Cable MSStat - Stat4 circuit 2

0.9906

Cable MSStat - Stat4 circuit 1

0.9906

Cable Stat4 - Stat3

0.9505

Cable Stat4 - Main bus bar

0.9833

Cable Stat1 - Stat3 circuit 1

0.966

 

 

Formulas

Formulas can be written by starting the value with an "=" sign. Use English function names and commas instead of semicolons.

 

Html

Formatting tags can be used in an html-oriented value, by starting the value with <html>. This works for FileIndex 1 to 9.

For example: <b>.....</b> for bold, <i>.....</i> for italic, <u>.....</u> for underlined, <br> for a new line.