title: How can we specify the columns DataType to string, number Datetime in Excel/SpreadSheet when Export from c#
body: <p>am using the following code to export the data to Excel from c#. I will Provide one sample image with this to know better what i needed.</p>
  
  <p>NOt only for a single column we cannot say this type is coming to a particular column in excel. during exporting of diffrent data</p>
  
  <p>the code am using is</p>
  
  <pre><code>            SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.
                      Create(savingFileName, SpreadsheetDocumentType.Workbook);
  
                  // Add a WorkbookPart to the document.
                  WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
                  workbookpart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook();
  
                  // Add a WorksheetPart to the WorkbookPart.
                  var worksheetPart = workbookpart.AddNewPart&lt;WorksheetPart&gt;();
                  var sheetData = new SheetData();
                  worksheetPart.Worksheet = new DocumentFormat.OpenXml.Spreadsheet.Worksheet(sheetData);
                  var bold1 = new System.Windows.Documents.Bold();
                  DocumentFormat.OpenXml.Spreadsheet.CellFormat cf = new DocumentFormat.OpenXml.Spreadsheet.CellFormat();
  
                  // Add Sheets to the Workbook.
                  DocumentFormat.OpenXml.Spreadsheet.Sheets sheets;
                  sheets = spreadsheetDocument.WorkbookPart.Workbook.
                      AppendChild&lt;DocumentFormat.OpenXml.Spreadsheet.Sheets&gt;(new DocumentFormat.OpenXml.Spreadsheet.Sheets());
  
                  // Append a new worksheet and associate it with the workbook.
                  var sheet = new Sheet()
                  {
                      Id = spreadsheetDocument.WorkbookPart.
                          GetIdOfPart(worksheetPart),
                      SheetId = sheetId,
                      Name = "Sheet" + sheetId
                  };
                  sheets.Append(sheet);
  
                  //Add Header Row. 
                  var headerRow = new Row();
                  headerRow.RowIndex = 10;
                  var cell=new Cell();
                  foreach (DataColumn column in dtCollection.Columns)
                  {
                      cell = new Cell
                      {
                          DataType = CellValues.String, CellValue = new CellValue(column.ColumnName.ToUpper())
                      };
                      headerRow.AppendChild(cell);
  
                  }
                  sheetData.AppendChild(headerRow);
  
                  foreach (DataRow row in dtCollection.Rows)
                  {
                      var newRow = new Row();
                      foreach (DataColumn col in dtCollection.Columns)
                      {
                          cell = new Cell
                          {
                              DataType = CellValues.String,
                              CellValue = new CellValue(row[col].ToString())
                          };
                          newRow.AppendChild(cell);
                      }
                      sheetData.AppendChild(newRow);
                  }
  
                  workbookpart.Workbook.Save();
                  spreadsheetDocument.Close();
  </code></pre>
  
  <p>The image is as Follows 
  <a href="https://i.stack.imgur.com/egrCa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/egrCa.png" alt="enter image description here"></a></p>
  
  <p>in this above pic you can see Debit and credit column it should be number but with my code it can be only string<br>
      Column Type</p>
  
  <ol>
  <li>Credit-Number</li>
  <li>Debit-Number</li>
  <li>Date- Date-time</li>
  <li>Code-String</li>
  <li>opening Balance-Number</li>
  </ol>
  
  <p>with the above requirement i need to export the datatable to excel in excel each column should be differnt datatype. how can i do this  can any one help me to complete my work</p>