相关疑难解决方法(0)

如何在导出前从GridView格式化列以显示excel中的所有数字?

我正在尝试将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++) …
Run Code Online (Sandbox Code Playgroud)

c# gridview

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

gridview ×1