Description
This model illustrates reading a table from an Excel spreadsheet with row and column dimension of magnitude 1. In addition, reading the same data using a named Excel range is demonstrated. This model is referenced in "Reading Parameter from Spreadsheet" and "Reading Parameter from Spreadsheet using pre-defined Excel Named Ranges" from the GDXXRW Documentation.
Category : GAMS Data Utilities library
Main file : GDXXRWExample5.gms includes : Test1.xlsx GDXXRWExample5.gms
$title Reading Parameter from Spreadsheet (GDXXRWExample5,SEQ=016)
$onText
This model illustrates reading a table from an Excel spreadsheet with row and
column dimension of magnitude 1. In addition, reading the same data using a
named Excel range is demonstrated.
This model is referenced in "Reading Parameter from Spreadsheet" and "Reading
Parameter from Spreadsheet using pre-defined Excel Named Ranges" from the
GDXXRW Documentation.
$offText
$callTool win32.msappavail Excel
$if errorlevel 1 $abort.noError "No Excel available"
Set
i 'row entries' / i1, i2 /
a 'column entries' / a1, a2, a3 /;
Parameter
data1(i,a) 'parameter values are read using the block range specification'
data4(i,a) 'parameter values are read using the named range specification';
* use an option file to increase readability
$onEcho > howToRead.txt
* read data1 using the block range specification
par=data1 rng=A1:D3 cDim=1 rDim=1
* read data4 using the named range specification (cell range name: 'parRange')
par=data4 rng=parRange cDim=1 rDim=1
$offEcho
$call gdxxrw Test1.xlsx @howToRead.txt trace=0
$ifE errorLevel<>0 $abort Error reading parameter from spreadsheet!
* load the data
$gdxIn Test1.gdx
$load data1 data4
$gdxIn
display data1, data4;
* Data Validation
Table exp_data1(i,a) 'expected_data1'
a1 a2 a3
i1 1 2 3
i2 4 5 6;
Set error01(i,a) 'unexpected value';
error01(i,a) = exp_data1(i,a)<>data1(i,a) or exp_data1(i,a)<>data4(i,a);
abort$card(error01) error01;