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.
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: http://photoadder.com/show-image.php?id=0ca30b7f4ba55fe359c889af62a278a4 (click to enlarge)
When I typed the single quote to the excel my self this is the result. Image:http://photoadder.com/show-image.php?id=48366a8093afc8555bcf7c990fc3648e
Here are parts of my 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<string> columnNames = new List<string>();
List<string> rows = new List<string>();
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<string> currentRow = new List<string>();
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();