User Tools

Site Tools


gams:export_only_rounded_numbers_from_gams_to_excel

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
gams:export_only_rounded_numbers_from_gams_to_excel [2010/06/18 13:07]
support
gams:export_only_rounded_numbers_from_gams_to_excel [2010/06/21 13:44] (current)
support
Line 2: Line 2:
 Q: // When unloading data from GAMS to Excel with GDX, is it possible to round numbers or choose the number of decimal to be included in the Excel files?// Q: // When unloading data from GAMS to Excel with GDX, is it possible to round numbers or choose the number of decimal to be included in the Excel files?//
  
-There is no explicit option to round numbers when writing to an Excel file, but you can round within GAMS before writing the data to GDX. The following will round the parameter abc to two decimal places ​and export it to Excel: ​ +There is no explicit option to round numbers when writing to an Excel file, but you can round within GAMS before writing the data to GDX. The following will round the parameter abc to two decimal placesexport it to Excel, and call Excel with the correct file extension (depending of the version of Excel installed)
 <​code>​ <​code>​
 +$if NOT set fn $set fn '​abc'​
 set i /i1*i3/; set i /i1*i3/;
 parameter abc(i); parameter abc(i);
Line 10: Line 10:
 abc(i) = round(abc(i),​2);​ abc(i) = round(abc(i),​2);​
 display abc; display abc;
-execute_unload 'abc.gdx' abc; +execute_unload '%fn%.gdx' abc; 
-execute '​GDXXRW.EXE ​abc.gdx par=abc rng=a1';​ +execute '​GDXXRW.EXE ​%fn%.gdx par=abc rng=a1'​
-execute '​shellexecute ​abc.xlsx';​+scalar R
 +execute '​xlstalk.exe -E %fn%.xls';​ 
 +R = errorlevel;​ 
 +if( R = 1, 
 +  ​execute '​shellexecute.exe %fn%.xls';​ 
 +else 
 +  execute '​shellexecute.exe %fn%.xlsx'
 +  );
 </​code>​ </​code>​
 +
 +
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/export_only_rounded_numbers_from_gams_to_excel.txt · Last modified: 2010/06/21 13:44 by support