GDXXRWExample11a.gms : Writing Sets and Parameter to Spreadsheet at Compile Time

Description

This program illustrates writing to an MS Excel file at compile time.
At first, a set is defined and written to spreadsheet while demonstrating the
values option. Afterwards, a parameter is generated and written to spreadsheet, too.


Category : GAMS Data Utilities library


Main file : GDXXRWExample11a.gms   includes :  GDXXRWExample11a.gms  Makedata.gms

$title Writing Sets and Parameter to Spreadsheet at Compile Time (GDXXRWExample11a,SEQ=022)

$onText
This program illustrates writing to an MS Excel file at compile time.
At first, a set is defined and written to spreadsheet while demonstrating the
values option. Afterwards, a parameter is generated and written to spreadsheet, too.
$offText

$callTool win32.msappavail Excel
$if errorlevel 1 $abort.noError "No Excel available"

* Writing Set to spreadsheet
Set x / element1 'explanatory text'
        element2
        element3 'previous element does not have explanatory text' /;

* unload set x and write to spreadsheet using a option file to increase readability
* while demonstrating the values option
$gdxOut writingSet.gdx
$unLoad x
$gdxOut

$onEcho > howToWrite.txt
hText="values: noData,,,values: yn,,,values: string" rng=Sheet1!A1
set=x rng=Sheet1!A2 rDim=1 values=noData
set=x rng=Sheet1!D2 rDim=1 values=yn
set=x rng=Sheet1!G2 rDim=1 values=string
$offEcho

$call gdxxrw writingSet.gdx output=writingSet.xlsx @howToWrite.txt trace=0
$ifE errorLevel<>0 $abort Error writing set to spreadsheet!
*-------------------------------------------------------------------------------


* Writing Parameter to spreadsheet
* Create the three dimensional parameter V by calling Makedata and write to spreadsheet afterwards
$call GAMS Makedata gdx=writingPar lo=%GAMS.lo%
$ifE errorLevel<>0 $abort Error generating parameter!

$call gdxxrw writingPar.gdx output=writingPar.xlsx par=V rng=A1 trace=0
$ifE errorLevel<>0 $abort Error writing parameter to spreadsheet!