title: How to create a CellValue for a Decimal With Format (#,###.##) in OpenXML
body: <p>I'm currently working in the requirement of export an Excel file by using Open XML framework. The problem that I have, is that one of the columns of this spreadsheet has to be decimal in format (#,###.##) which has to allow sums. I could export the Excel perfectly in this format by using the following method:</p>
  
  <pre><code>private static Cell CreateTextCell(string header, UInt32 index, object text, CellStyleIndex cellStyle)
  {
      var cell = new Cell
      {
          DataType = CellValues.InlineString,
          CellReference = header + index,
          StyleIndex = (UInt32)cellStyle
      };
  
      var istring = new InlineString();
      var t = new Text { Text = text.ToString() };
      istring.AppendChild(t);
      cell.AppendChild(istring);
      return cell;
  }
  </code></pre>
  
  <p>As you can see, I'm specifying the <em>StyleIndex</em> which applies the format that I mentioned. But the problem with this is that Excel recognizes this value as a text:</p>
  
  <p><a href="https://i.stack.imgur.com/B6bFV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B6bFV.png" alt="enter image description here"></a></p>
  
  <p>That's why I tried to create a new method which is invoked as soon I want to create a decimal in the file:</p>
  
  <pre><code>private static Cell CreateValueCell(string header, UInt32 index, decimal value, CellStyleIndex cellStyle)
  {
       var cell = new Cell
       {
           DataType = CellValues.Number,
           CellReference = header + index,
           StyleIndex = (UInt32)cellStyle,
           CellValue = new CellValue(value.ToString())
       };
  
       return cell;
  }
  </code></pre>
  
  <p>By doing this, I reach how to convert as a number, but I lose the decimal places as you can see in the following image:</p>
  
  <p><a href="https://i.stack.imgur.com/Tjl8V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tjl8V.png" alt="enter image description here"></a></p>
  
  <p>I saw a class named <strong>DecimalValue</strong> but I couldn't figure out how to append it to the cell. Any thoughts about how to solve it? </p>