Search code examples
c#excelepplus

C# - Read MergedCells range in EPPlus


How to read the value of range that is Merged with EPPlus?

Lets say the range "G15:G18" is merged. How do I retrieve the text inside that range?

I've tried this, but without success:

string txt = ws.Cells["G15:G18"].Value.ToString();

Thanks.


Solution

  • Looking better at the issue, I finally understood that what I was doing was actually bringing a collection of results, where only the first item has a value.

    So, basically, this code:

    string txt = ws.Cells["G15:G18"].Value.ToString();
    

    would return an array like with the text for all the cells in the range.

    But except for the first cell in the array, all cells are empty. Only the first cell hold the Value for the whole range.

    What I did is as simple as this:

    string val = ws.Cells["G15:G18"].First().Value.ToString();
    

    It worked fine.