read from excel file in CPLEX Studio, cell contain a list

22 Views Asked by At

I am getting the data from the "data.xlsx" file using this code:

this part from the .mod file int n=...; range items = 1..n; int values[items] = ...;

and this part from .dat file: n from SheetRead(excelsheet, "Sheet1!A3"); values from SheetRead(excelsheet, "Sheet1!A7"); the list of values is in the cell A7, i want to load it into the var values, by this manner i faced an error which says: **Exception from IBM ILOG Concert excel size of the range is not the **

load a list from excel file in cplex

1

There are 1 best solutions below

0
Alex Fleischer On

2 steps :

First you read the cell as a string.

In excel OPL, see

SheetConnection s("read1cell.xlsx");

value from SheetRead(s,"B1");

value2 to SheetWrite(s,"B5");

and then with OPL scripting you can turn the string into an array of values

string s="1;2;8;1000";

int arsize;

execute
{
  ar=s.split(";");
  writeln("size =",ar.length);
  arsize=ar.length;
}

range r=1..arsize;
int resultarray[r];

execute
{
  ar=s.split(";");
  for(var i in r) resultarray[i]=Opl.atoi(ar[i-1]);
  writeln("resultarray = ",resultarray);
}

/*

which gives

size =4
resultarray =  [1 2 8 1000]

*/