Merge

Top  Previous  Next

When writing to a spreadsheet one can control data handling and set matching using the Merge command line parameter.  When 'Merge' is active the only data that will be written to the spreadsheet are those data for which the set element names match row and column labels that are in the spreadsheet already.  Also under Merge spreadsheet cells for which there is no matching row/column pair will not be changed.  Also element ordering is explicitly specified overriding the default that would occur as controlled by the GAMS element ordering rules and the unique element list as discussed in the Rules for  Item Capitalization and Ordering chapter.

Example:

Suppose I have a range in a spreadsheet that appears as in the sheet2 page of the workbook gdxxrwss.xls with exactly the same contents in the range i1:n4.

 

_img97

 

and use the commands (gdxxrwskipempty.gms)

 

$call"Gdxxrw GDXse.gdx o=gdxxrwss.xls  par=moded4 Rng=sheet2!b1:g4 rdim=2 cdim=1 merge"

$call "Gdxxrw GDXse.gdx o=gdxxrwss.xls  par=moded4 Rng=sheet2!b8 rdim=2 cdim=1"

 

then the resultant spreadsheet looks like

 

_img98

 

where the portion in rows b8-f12 is what happens without the merge and the part in rows 1-4 is what happened with it.  Note that the column and row orders vary and the san francisco chicago row is missing since it is not mentioned in the labels before the merge operation and the horse column is present with it's data left alone.

Notes:

Using the merge option will force the data to be presented in the order in which the row and column labels are entered.
GDX file contents that do not have matching row/column pair of named elements in the spreadsheet will be overlooked.
A write under a merge option addressing a blank area of a spreadsheet will always be blank as there will not be matching set elements.
The matching of labels is not case sensitive.
Warning: The Merge option will clear the Excel formulas in the rectangle used, even if the cells do not have matching row / column headings in the GDX file.  Cells containing strings or numbers are not affected.