Description
This program illustrates reading a table from an Excel spreadsheet. It contains the same data as in GDXXRWExample5.gms but organized differently. Unlike GDXXRWExample5.gms, this example also reads set data. Additionally, this program offers writing and reading GDXXRW command options from a file. This model is referenced in "Reading Parameter from Spreadsheet with Duplication" from the GDXXRW Documentation.
Category : GAMS Data Utilities library
Main file : GDXXRWExample6.gms includes : Test1.xlsx GDXXRWExample6.gms
$title Reading Parameter from Spreadsheet with Duplication (GDXXRWExample6,SEQ=017)
$onText
This program illustrates reading a table from an Excel
spreadsheet. It contains the same data as in GDXXRWExample5.gms
but organized differently. Unlike GDXXRWExample5.gms,
this example also reads set data. Additionally, this program
offers writing and reading GDXXRW command options from a file.
This model is referenced in "Reading Parameter from Spreadsheet with
Duplication" from the GDXXRW Documentation.
$offText
$callTool win32.msappavail Excel
$if errorlevel 1 $abort.noError "No Excel available"
Set
i 'row entries'
a 'column entries';
Parameter data2(i,a);
$call gdxxrw Test1.xlsx par=data2 rng=EX2!A1 rDim=2 dSet=I rng=EX2!A1 rDim=1 dSet=A rng=EX2!B1 rDim=1 trace=0
$ifE errorLevel<>0 $abort Error reading from spreadsheet!
* Alternatively, the above statement can be commented and the lines below can be uncommented
* An option file will be written and used to increase readability
* $onEcho > example6.txt
* par =data2 rng=EX2!A1 rDim=2
* dSet=I rng=EX2!A1 rDim=1
* dSet=A rng=EX2!B1 rDim=1
* $offEcho
* $call gdxxrw Test1.xlsx @example6.txt
* $ifE errorLevel<>0 $abort Error reading from spreadsheet using an option file!
$gdxIn Test1.gdx
$load i a data2
$gdxIn
display i, a, data2;
* Data Validation
Table exp_data2(i,a) 'expected_data2'
a1 a2 a3
i1 1 2 3
i2 4 5 6;
Set error01(i,a) 'unexpected value';
error01(i,a) = exp_data2(i,a)<>data2(i,a);
abort$card(error01) error01;