And I need to output the values as follows:
"API Docs Portal : op-api-docs"
"Big Ideas : op-bigideas"
"Education : op-education"
....
I've tried something but it doesn't works as expected...
for (var x = 1; x <= reportValue.GetLength(0); x++)
{
for (var y = 1; y <= reportValue.GetLength(1); y++)
{
if (reportValue[x, y] != null)
{
var id = reportValue[x, y];
var name = reportValue[x, y + 1];
var result = name + " : " + id;
}
}
}
Note:
This is how I get the reportValue
array (using C# Interop):
var reportLast = ws.Range["A" + ws.Rows.Count].End(Excel.XlDirection.xlUp).Row;
var rngReport = (Excel.Range)ws.Range[ws.Cells[2, 1], ws.Cells[reportLast, 2]];
var reportValue = rngReport.Cells.Value;
It's not clear why you've got two loops here. You always want the same two elements for each row - index 1 and index 2. So you just need:
for (var x = 1; x <= reportValue.GetLength(0); x++)
{
var id = reportValue[x, 1];
var name = reportValue[x, 2];
var result = name + " : " + id;
// Use result
}
That will fetch [1, 1] : [1, 2]
, then [2, 1] : [2, 2]
, then [3, 1] : [3, 2]
etc - which looks like it's exactly what you need.
See more on this question at Stackoverflow