title: DataTable normalize blanks cells
body: <p>I have not found a method to normalize a DataTable that came from an Excel with merged cells. When I get the DataTable from that Excel, only the first cell has the value, others are blank.</p>
  
  <p>An example of this DataTable is:</p>
  
  <p><a href="https://i.stack.imgur.com/GC4If.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GC4If.jpg" alt="enter image description here"></a></p>
  
  <p>and the expected result:</p>
  
  <p><a href="https://i.stack.imgur.com/KhVtE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KhVtE.jpg" alt="enter image description here"></a></p>
  
  <p>To summarize: blanks cells should be completed with the value of the next cell above with a value, since is what was happened with the Excel merge of cells.</p>
  
  <p>I'm using Excel.dll to read this Excel, didn't provide the autofill of cells, so that's why I'm searching for a method inside C#.</p>
  
  <p>I suppose that logic should be: if a cell is blank, use the upper cell as a value. The logic appears clear but I have issues trying to get the code to apply it.</p>
  
  <p>This is a sample, but at the end, I'm looking for a method to do this whenever columns or rows have the datatable.</p>
  
  <p><strong>Edit</strong>:
  Thanks for your quicky feedback.
  Attached what i have so far for just only one column and with errors since doesn't take care of the first and last row, but is the idea... what i try to achieve is to have a method for any amount of cols and rows (could be ok if cols are fixed with names, and then if i have more columns i will adapt).</p>
  
  <pre><code>        private void NormalizeDataTable(DataTable dtRawTable)
      {
  
          DataTable dtFinalized = new DataTable();
          dtFinalized.Columns.Add("Col1", typeof(String));
  
          string previousValue = "";
  
          for (int index = 0; index &lt;= dtRawTable.Rows.Count; index++)
          {
              DataRow dr = dtFinalized.NewRow();
  
  
  
              if (index != 0 || index == dtRawTable.Rows.Count -1)
              {
  
                  if (dtRawTable.Rows[index]["Modelo"].ToString() == "")
                  {
                      dr["Col1"] = previousValue;
                  }
                  else
                  {
                      dr["Col1"] = Convert.ToString(dtRawTable.Rows[index]["Modelo"].ToString());
                      previousValue = (string)dr["Col1"];
                  }
              }
  
              dtFinalized.Rows.Add(dr);
              dtFinalized.AcceptChanges();
  
  
          }
      }
  </code></pre>