Download IBM ILOG OPL IDE Tutorials

Transcript
The oil sheet data file
Double-click the oilSheet.dat file in the project tree to see the contents of the data file.
Data file for the Oil Sheet example (oilSheet.dat)
SheetConnection sheet("oilSheet.xls");
Gasolines from SheetRead(sheet,"gas!A2:A4");
Oils from SheetRead(sheet,"oil!A2:A4");
Gas from SheetRead(sheet,"gas!B2:E4");
Oil from SheetRead(sheet,"oil!B2:E4");
MaxProduction = 14000;
ProdCost = 4;
a to SheetWrite(sheet,"RESULT!A2:A4");
Blend to SheetWrite(sheet,"RESULT!B2:D4");
The data file starts with the SheetConnection statement used to connect to the spreadsheet.
Note: You can have multiple data files and, within any of them, multiple connections to
spreadsheets.
Connecting to the spreadsheet from OPL
The connection is established by the following statement:
Connecting to a spreadsheet (MS Excel)
SheetConnection sheet("oilSheet.xls");
The name of the spreadsheet file in quotes is passed as an argument.
Note: You do not need to specify the full path name. Relative paths are resolved using the
directory of the current .dat files.
Reading from the spreadsheet
Reading spreadsheet columns
You can read data from a column in any sheet into an OPL array using the SheetRead
statement, as in the data file oilSheet.dat.
Reading spreadsheet columns (oilSheet.dat)
Gasolines from SheetRead(sheet,"gas!A2:A4");
Oils from SheetRead(sheet,"oil!A2:A4");
I B M
I L O G
O P L
I D E
T U T O R I A L S
69