Saturday, February 6, 2010

Writing Excel files in GAMS

GDXXRW has troubles in writing to an Excel spreadsheet when it is already open. One way to deal with this is to make the spreadsheet shared but that may cause slow performance. Here is an alternative. The following code helps to close the spreadsheet and reopen it afterwards:

$set xlsfile results3.xlsx
….
* close xls file
$call =xlstalk.exe -C %xlsfile%
….
execute_unload ….
….
execute '=gdxxrw @cmd.txt';
* this sometimes can block
* execute '%xlsfile%';
* this may be better:
execute 'shellexecute "%xlsfile%"';

No comments:

Post a Comment