title: EPPLUS how to know the format of the Worksheet cell
body: <p>I am using EPPlus to read excel sheets and load the data into datatable to perform further operations and then save back the modified data to the excel file.</p>
  
  <p>The below code checks if the cell value is a float value then it converts the float value to datetime. </p>
  
  <p>The code works fine when the cell value is a date eg: Invoice Date = 42009 , but it converts the not a date value like eg : amount = 10 to a date.</p>
  
  <p>Is there any way in EPPlus library from which i can determine the format of the cell (i.e General/date/number etc) ?</p>
  
  <pre><code>float floatValue;
  
  if (float.TryParse(Convert.ToString(oSheet.Cells[i, j].Value), out floatValue)
                                  &amp;&amp; Convert.ToString(oSheet.Cells[i, j].Style.Numberformat.Format).Contains("[$-409]d\\-mmm\\-yy;@"))
    {
        dr[j - 1] = String.Format("{0:d-MMM-yy}", DateTime.FromOADate(floatValue));
    }
    else
    {
         DateTime date;
  
         if (DateTime.TryParse(Convert.ToString(oSheet.Cells[i, j].Value), out date))
          {
                  dr[j - 1] = String.Format("{0:d-MMM-yy}", date);
          }
          else
          {
                 dr[j - 1] = Convert.ToString(oSheet.Cells[i, j].Value).Trim();
          }
     }
  </code></pre>