title: How do I add single quote to an EXCEL cell using ASP.NET C# code/program that reads data from an SQL Table and producing an EXCEL report from it?
body: <p>How do I add an additional single quote character to an EXCEL/CSV cell when I have an ASP.NET C# code/program that reads data from an SQL Table and producing an EXCEL report from it? So that the number produced is not scientific value , it would be exact (its an additional single quote character to a cell that will have data). I need to add the single quote before the data, but when added, the single quote itself will not show, rather, the exact number will show.</p>
  
  <p>The problem is in the image below, from the SQL Result it is an exact number, but when the code is used it is rounded to scientific value.
  Image:  <a href="http://photoadder.com/show-image.php?id=0ca30b7f4ba55fe359c889af62a278a4" rel="nofollow">http://photoadder.com/show-image.php?id=0ca30b7f4ba55fe359c889af62a278a4</a> (click to enlarge)</p>
  
  <p>When I typed the single quote to the excel my self this is the result.
  Image:<a href="http://photoadder.com/show-image.php?id=48366a8093afc8555bcf7c990fc3648e" rel="nofollow">http://photoadder.com/show-image.php?id=48366a8093afc8555bcf7c990fc3648e</a></p>
  
  <p>Here are parts of my code</p>
  
  <pre><code>public DataTable GetData()
  {
     var dataTable = new DataTable();
  
     SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString);
     conn.Open();
     string query = "select * from table abc";
  
     SqlCommand cmd = new SqlCommand(query, conn);
  
     DataTable t1 = new DataTable();
     using (SqlDataAdapter a = new SqlDataAdapter(cmd))
     {
         a.Fill(t1);
     }
     return t1;
  }
  #endregion
  
  
  protected void btnGenerateReport_Click(object sender, EventArgs e)
  {
      System.Diagnostics.Debug.WriteLine("PLaccount system on click");
  
      var dataTable = GetData();
  
      StringBuilder builder = new StringBuilder();
      List&lt;string&gt; columnNames = new List&lt;string&gt;();
      List&lt;string&gt; rows = new List&lt;string&gt;();
  
      foreach (DataColumn column in dataTable.Columns)
      {
          columnNames.Add(column.ColumnName);
          if (column.ColumnName.ToString() == "PL_ACCOUNT_NUMBER")
          {
  
              System.Diagnostics.Debug.WriteLine("PLaccount system match");
  
          }
      }
  
      builder.Append(string.Join(",", columnNames.ToArray())).Append("\n");
  
      foreach (DataRow row in dataTable.Rows)
      {
          List&lt;string&gt; currentRow = new List&lt;string&gt;();
  
          foreach (DataColumn column in dataTable.Columns)
          {
              object item = row[column];
  
              currentRow.Add(item.ToString());
          }
  
          rows.Add(string.Join(",", currentRow.ToArray()));
      }
  
      builder.Append(string.Join("\n", rows.ToArray()));
  
      Response.Clear();
      Response.ContentType = "text/csv";
      Response.AddHeader("Content-Disposition", "attachment;filename=myfilename.csv");
      Response.Write(builder.ToString());
      Response.End();
  </code></pre>