title: how to get merged cells of excel file only one time in c# using microsoft.office.interop.excel
body: <p>i am reading excel file in C# using microsoft.office.interop.excel. when the file having merged cells it is looping by containing number of cells in merged cell while i want the merged area at once</p>
  
  <p>here is my method</p>
  
  <pre><code>public void ImportXLX()
      {
          Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
  
          Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Open(@"C:\Users\Vipin\Desktop\Sheets\MyXL6.xlsx", Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                  Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                  Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                  Type.Missing, Type.Missing);
  
          int workSheetCounts = wb.Worksheets.Count;
  
          for (int sheetCounter = 1; sheetCounter &lt;= workSheetCounts; sheetCounter++)
          {
              Microsoft.Office.Interop.Excel.Worksheet workSheet = wb.Sheets[sheetCounter];
  
              Range excelRange = workSheet.UsedRange;
              Range objRange = null;
  
              int rowCount = 0;
              float totalRowWidth = 0;
              foreach (Microsoft.Office.Interop.Excel.Range row in excelRange.Rows)
              {
                  rowCount++;
                  totalRowWidth = row.Width;
                  int colCount = 0;
  
                  foreach (Microsoft.Office.Interop.Excel.Range c in row.Cells)
                  {
                      colCount++;
                      objRange = workSheet.Cells[rowCount, colCount];
  
                      double width = 0;
                      double height = 0;
                      string colVal = null;
  
                      if (objRange.MergeCells)
                      {
                          colVal = Convert.ToString(((Range)objRange.MergeArea[1, 1]).Text).Trim();
                          width = objRange.MergeArea.Width;
                          height = objRange.MergeArea.Height;
  
  
                      }
                      else
                      {
                          colVal = Convert.ToString(objRange.Text).Trim();
                          width = objRange.Width;
                          height = objRange.Height;
                      }
                      Debug.Write("objRange = " + objRange + " rowCount = " + rowCount + " Width = " + width + " height = " + height + "TotalColumnWidth = " + totalRowWidth + "TotalRowHeight = " + totalColHeight + " \n ");
                  }
              }
          }
          app.Quit();
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/7PkHv.png" alt="enter image description here"></p>
  
  <p>here is the excel file screenshot</p>
  
  <p>in this i want [3,1] [4,1] [5,1] [6,1] [7,1][8,1][9,1] cell just once in loop with its complete width and height</p>