larrydavid
Programmer
Hello,
Using ASP.NET 4.0 with VS 2010 Ultimate and SQL Server 2005
I am able to export to a .csv file fine with this code, but am having a problem trying to pass a long numeric value into the first column without Excel trying to put a formula notation on it. Here is the code, output and what I am trying to get:
protected void BtnExportGrid_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition","attachment;filename=" + "_" + userID + "_" +
DateTime.Now.ToShortDateString() + "_" + ".csv");
Response.Charset = "";
Response.ContentType = "application/csv";
//Response.Write(this.MsoFormats);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
StringBuilder sb = new StringBuilder();
for (int k = 0; k < gvSubmissionData.Columns.Count; k++)
{
//add separator
sb.Append(gvSubmissionData.Columns[k].HeaderText + ',');
}
//append new line
sb.Append("\r\n");
for (int i = 0; i < gvSubmissionData.Rows.Count; i++)
{
for (int k = 0; k < gvSubmissionData.Columns.Count; k++)
{
//add separator
sb.Append(gvSubmissionData.Rows.Cells[k].Text + ',');
}
//append new line
sb.Append("\r\n");
}
Response.Output.Write(sb.ToString());
Response.Flush();
Response.End();
}
Here is the output:
Claim Type Amount Load Date
2.01014E+14 Test 350 12/15/2011
2.01014E+14 Test 909.25 12/15/2011
2.01009E+14 Test 638.68 12/15/2011
2.00911E+14 Test 660.25 12/15/2011
Here is what I want:
Claim Type Amount Load Date
201014479884700 Test 350 12/15/2011
201014479884800 Test 909.25 12/15/2011
201009179891500 Test 638.68 12/15/2011
200910679841500 Test 660.25 12/15/2011
Any help would be greatly appreciated.
Thanks,
Larry
Using ASP.NET 4.0 with VS 2010 Ultimate and SQL Server 2005
I am able to export to a .csv file fine with this code, but am having a problem trying to pass a long numeric value into the first column without Excel trying to put a formula notation on it. Here is the code, output and what I am trying to get:
protected void BtnExportGrid_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition","attachment;filename=" + "_" + userID + "_" +
DateTime.Now.ToShortDateString() + "_" + ".csv");
Response.Charset = "";
Response.ContentType = "application/csv";
//Response.Write(this.MsoFormats);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
StringBuilder sb = new StringBuilder();
for (int k = 0; k < gvSubmissionData.Columns.Count; k++)
{
//add separator
sb.Append(gvSubmissionData.Columns[k].HeaderText + ',');
}
//append new line
sb.Append("\r\n");
for (int i = 0; i < gvSubmissionData.Rows.Count; i++)
{
for (int k = 0; k < gvSubmissionData.Columns.Count; k++)
{
//add separator
sb.Append(gvSubmissionData.Rows.Cells[k].Text + ',');
}
//append new line
sb.Append("\r\n");
}
Response.Output.Write(sb.ToString());
Response.Flush();
Response.End();
}
Here is the output:
Claim Type Amount Load Date
2.01014E+14 Test 350 12/15/2011
2.01014E+14 Test 909.25 12/15/2011
2.01009E+14 Test 638.68 12/15/2011
2.00911E+14 Test 660.25 12/15/2011
Here is what I want:
Claim Type Amount Load Date
201014479884700 Test 350 12/15/2011
201014479884800 Test 909.25 12/15/2011
201009179891500 Test 638.68 12/15/2011
200910679841500 Test 660.25 12/15/2011
Any help would be greatly appreciated.
Thanks,
Larry