The following chunk of code grabs all the cells and filters it down to just the one we're trying to find...
Cell theCell = wsPart.Worksheet.Descendants<Cell>().
Where(c => c.CellReference == addressName).FirstOrDefault();
If you remove the Where(...)
, that should give you all the cells...
var cells = wsPart.Worksheet.Descendants<Cell>();
Now that you have that, you can take the chunk of code inside the if (theCell != null) { ... }
block, make it method that takes a Cell
(I called it ProcessCell
here, it'd need to be a static
function that returns a string
), and call it inside a foreach
loop, like this:
var results = new List<String>();
foreach cell in cells
{
results.Add(ProcessCell(cell));
}
and then just return your results!
return results;
Technically I didn't answer your question since the return type is a List<String>
instead of an array, but I think you can figure that part out if it's really necessary ;)