title: How to get value from merged-cells in Excel document using OpenXML and C#
body: <p>I have problem with merged cells. If I have value in first cell (B3) and this cell is merged with some others cells (for example C3, D3, E3, F3, F4) - in Excel document I can see only one value. This is great, but I would like to get from my GetCellValue function the same B3 value, when I ask for C3, D3, E3, F3 value.</p>
  
  <p>I suppose it is necessary to find all merged cells list and read value from the first one - but how to do this using OpenXml?</p>
  
  <pre><code>    public string GetCellValue(char ch, int y)
      {
          WorksheetPart wsPart = GetWorksheetPart(_sheetName);
          var addressName = new StringValue(ch + "" + y);
  
          Cell cell = wsPart.Worksheet.Descendants&lt;Cell&gt;().
              Where(c =&gt; c.CellReference.Value == addressName).FirstOrDefault();
  
          if (cell == null)
              return null;
  
          return cell.InnerText;
      }
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>I have found partial solution (finding merged column names in OpenXML):</p>
  
  <pre><code>        List&lt;MergeCells&gt; mergeCells;
          WorksheetPart wsPart = GetWorksheetPart(_sheetName);
          if (wsPart.Worksheet.Elements&lt;MergeCells&gt;().Count() &gt; 0)
          {
              mergeCells = wsPart.Worksheet.Elements&lt;MergeCells&gt;().ToList();
              string cells = mergeCells[0].OuterXml;
          }
  </code></pre>