load data from excel with specific structure

Dear all,

Instead of writing table g (as you can see in the code) in gams, i wanna load it from excel.

set m /1*3/;
alias (m,n);

Table g(m,n,*)
            a                b
1.2        0.00375     0.00275
1.3        0.00375     0.0035
2.3        0.001875    0.0015
;

I have written some code. however, it doesn’t work. Could someone modify or give me some idea?
Thanks you !!!

set m /1*3/;
alias (m,n);
parameter g(*,*) ;
$onecho> p.txt
Par=g        rng=DG!C4:E7   rdim=1   cdim=1
$offecho

$call GDXXRW p.xlsx Squeeze=N trace=3 @p.txt
$gdxin p.gdx
$load g
$gdxin
display g;

p.xlsx (7.92 KB)

p.xlsx (8.17 KB)
Hi dasa,

See code below, should be working with attached XLSX. Made some small changes, but most important is that every dimension needs its own column/row in Excel.

Regards,
GFA


set m /1*3/;
alias (m,n);
parameter g(*,*,*) ;
$onecho> p.txt
Par=g        rng=S1!B4:E7   rdim=2   cdim=1
$offecho

$call GDXXRW i='p.xlsx' 'o=p.gdx' Squeeze=N trace=3 @p.txt
$gdxin 'p.gdx'
$load g
$gdxin
display g;

Dear GFA,

Thanks for your response. it’s work great. but how to use this g(,,*) after we load it ? i.e. we want to use the value of g(1,2,‘a’).

Best regards,

Dear dasa,

Try using “” for example:
g(“1”,“2”,“a”)

Also have a look here for more information on GAMS syntax: https://www.gams.com/latest/docs/UG_MAIN.html#UG_Language_Environment

Best,
GFA