I can't find how to implement jagged array using for loop. I have tried, however only the last smaller array becomes jagged arrays item.
string[][] allSheets = new string[size][];
This is how I declare. Below is how I get allSheets[number] element.
public string[] get_Sheets(int colNum)
{
CellReference[] cr = new CellReference[rows_.Length];
ISheet sheet = wb.GetSheetAt(0);
IRow[] row = new IRow[rows_.Length];
ICell[] cell = new ICell[rows_.Length];
string[] cellResult = new string[rows_.Length];
for (int i = 0; i < cr.Length; i++)
{
cr[i] = new CellReference(rows_[i] + colNum);
row[i] = sheet.GetRow(cr[i].Row);
cell[i] = row[i].GetCell(cr[i].Col);
cellResult[i] = cell[i].ToString();
}
return cellResult;
}
My two for loops looks something like this:
for (int ii = 0; ii < size; ii++)
{
for (int jj = 2; jj < size; jj++)
{
allSheets[ii] = get_Sheets(jj);
}
}
Notice how I started jj with 2. I had to since it's how excel files work..
You could clearly see that despite everything my every allSheets[ii] would become the last possible j number in for loop. I had tried to swap the loops so i starts first, however result is the same.