title: How to enter the zero in front of numbers in excel?
body: <p>I have an application written in C# which extracts the data from Datagridview to excel. My problem is when I have a number like 010498 when I export to excel become 10498, without the zero (0) at the beginning. I want there to be zero (0). Is there any possible solution, either writing code in C # within the application or via excel?<br>
  Thanks and sorry for bad English.</p>
  
  <p><img src="https://i.stack.imgur.com/2BabX.png" alt="In the Datagridview"></p>
  
  <p><img src="https://i.stack.imgur.com/5qFgu.png" alt="After export to excel"></p>
  
  <p>In the first picture seems to datagridview and in the second picture how after export to excel. In cells A3, F3, F4 missing zero (0) at the beginning. Any Solution how i can fix it? Thanks.<br>
  Code of Export to Excel.</p>
  
  <pre><code>private void excel_toolstripmenuitem_Click(object sender, EventArgs e)
      {
          Microsoft.Office.Interop.Excel.Application excelApp = null;
          try
          {
              // instantiating the excel application class
              object misValue = System.Reflection.Missing.Value;
              excelApp = new Microsoft.Office.Interop.Excel.Application();
              Microsoft.Office.Interop.Excel.Workbook currentWorkbook = excelApp.Workbooks.Add(Type.Missing);
              Microsoft.Office.Interop.Excel.Worksheet currentWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)currentWorkbook.ActiveSheet;
              currentWorksheet.Columns.ColumnWidth = 18;
              if (dg1.Rows.Count &gt; 0)
              {
                  currentWorksheet.Cells[1, 1] = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString();
                  int i = 1;
                  foreach (DataGridViewColumn dgviewColumn in dg1.Columns)
                  {
                      // Excel work sheet indexing starts with 1
                      currentWorksheet.Cells[2, i] = dgviewColumn.Name;
                      ++i;
                  }
                  Microsoft.Office.Interop.Excel.Range headerColumnRange = currentWorksheet.get_Range("A2", "AY2");
                  headerColumnRange.Font.Bold = true;
                  headerColumnRange.Font.Color = 0xFF0000;
                  int rowIndex = 0;
                  for (rowIndex = 0; rowIndex &lt; dg1.Rows.Count; rowIndex++)
                  {
                      DataGridViewRow dgRow = dg1.Rows[rowIndex];
                      for (int cellIndex = 0; cellIndex &lt; dgRow.Cells.Count; cellIndex++)
                      {
                          currentWorksheet.Cells[rowIndex + 3, cellIndex + 1] = dgRow.Cells[cellIndex].Value;
                      }
                  }
                  Microsoft.Office.Interop.Excel.Range fullTextRange = currentWorksheet.get_Range("A1", "AY" + (rowIndex + 1).ToString());
                  fullTextRange.WrapText = true;
                  fullTextRange.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;
              }
  
              using (SaveFileDialog exportSaveFileDialog = new SaveFileDialog())
              {
                  exportSaveFileDialog.Title = "Save as";
                  exportSaveFileDialog.Filter = "Microsoft Office Excel Workbook(*.xls)|*.xls";
  
                  if (DialogResult.OK == exportSaveFileDialog.ShowDialog())
                  {
                      string fullFileName = exportSaveFileDialog.FileName;
  
                      currentWorkbook.SaveAs(fullFileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, System.Reflection.Missing.Value, misValue, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlUserResolution, true, misValue, misValue, misValue);                      
                      currentWorkbook.Saved = true;
                      MessageBox.Show("The export was successful", "Export to Excel", MessageBoxButtons.OK, MessageBoxIcon.Information);
                  }
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          finally
          {
              if (excelApp != null)
              {
                  excelApp.Quit();               
                  excelApp = null;
              }
          }
      }
  </code></pre>