title: Using NPOI, how do I return a cell value as it has been formatted by Excel?
body: <p>Using <a href="https://npoi.codeplex.com/" rel="nofollow">NPOI</a>, is there any buildin possibility to format a cell value (especially numeric and date values) as it has been <a href="https://support.office.com/en-us/article/Number-format-codes-5026bbd6-04bc-48cd-bf33-80f18b4eae68?ui=en-US&amp;rs=en-US&amp;ad=US" rel="nofollow">formatted by Excel</a>?</p>
  
  <p>If not what would be the best way to implement it? I thought of a formatstring converter from Excel-formatstrings to C#-formatstrings?</p>
  
  <p>The following example assumes the Excel-formatstring and the C#-formatstring are the same. So it works for some basic formatstrings like: "#,##0.00"</p>
  
  <pre><code>using NPOI.SS.UserModel;
  
  ICell cell = workbook.GetSheet("table1").GetRow(0).GetCell(0);
  string value = null;
  
  if(cell.CellType == CellType.String) {
      value = cell.StringCellValue;
  } else if(cell.CellType == CellType.Numeric) {
      string formatString = cell.CellStyle.GetDataFormatString();
  
      if(DateUtil.IsCellDateFormatted(cell)) {
          value = cell.DateCellValue.ToString(formatString);
      } else {
          value = cell.NumericCellValue.ToString(formatString);
      }
  } else [...]
  </code></pre>