Я пытаюсь экспортировать GridView в Excel, и у меня есть столбец с последовательностью чисел, например 1245333325364. Когда я запускаю запрос для GridView, я вижу полное число, но при экспорте в Excel все, что я вижу1.00133E + 12 в этом столбце.Я знаю, что пользователь может изменить это в Excel, но не все файлы открываются после экспорта, они просто сохраняют его прямо в каталоге.Я действительно хотел бы изменить формат столбца в процессе экспорта, а не делать так, чтобы пользователь сделал это, прежде чем сохранить файл.Я выполняю экспорт в C #, любая помощь будет очень полезна.
Код, который я использую для экспорта GridView, выглядит примерно так:
protected void exporttoexcel_Click(object sender, EventArgs e)
{
string date = DateTime.Now.ToString("MM-dd-yyyy");
PrepareGridViewForExport(GridView1);
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" + date + "_" + CHROUT.Text + "_Trailer_" + TRAILER.Text);
Response.Charset = "''";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.DataBind();
GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
GridView1.HeaderRow.Cells[0].Style.Add("width", "105px");
GridView1.HeaderRow.Cells[0].Style.Add("background-color", "#CCCCCC");
GridView1.HeaderRow.Cells[1].Style.Add("background-color", "#CCCCCC");
GridView1.HeaderRow.Cells[2].Style.Add("background-color", "#CCCCCC");
GridView1.HeaderRow.Cells[3].Style.Add("background-color", "#CCCCCC");
GridView1.HeaderRow.Cells[4].Style.Add("background-color", "#CCCCCC");
GridView1.HeaderRow.Cells[5].Style.Add("background-color", "#CCCCCC");
GridView1.HeaderRow.Cells[6].Style.Add("background-color", "#CCCCCC");
GridView1.HeaderRow.Cells[7].Style.Add("background-color", "#CCCCCC");
for (int i = 0; i < GridView1.Rows.Count; i++)
{
GridViewRow row = GridView1.Rows[i];
row.BackColor = System.Drawing.Color.White;
row.Attributes.Add("class", "texmode");
if (i % 2 != 0)
{
row.Cells[0].Style.Add("background-color", "#f0f0f0");
row.Cells[1].Style.Add("background-color", "#f0f0f0");
row.Cells[2].Style.Add("background-color", "#f0f0f0");
row.Cells[3].Style.Add("background-color", "#f0f0f0");
row.Cells[4].Style.Add("background-color", "#f0f0f0");
row.Cells[5].Style.Add("background-color", "#f0f0f0");
row.Cells[6].Style.Add("background-color", "#f0f0f0");
row.Cells[7].Style.Add("background-color", "#f0f0f0");
}
}
GridView1.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .text { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}