从C#导出到XLS文件

问题描述:





我将数据从数据网格视图导出到XLS文件,我的列有String值,但值是数字。当它导出数字的列像这样3.5245E + 14。如何删除+和我应该只得到数字。



请帮助





问候

Nirmala Sarvanan

Hi,

I am exporting a data from Data grid view to XLS file and i have column which is has String values but values are numbers. when it exported the column with numbers are coming like 3.5245E+14 like this. how to remove the + and i should get only the numbers.

Pls help


Regards
Nirmala Sarvanan





这是一个简单的导出到excel代码,导出到excel没有任何问题。

试试这个...



Hi,

Here is a simple export to excel code that exports to excel without any problems.
Try this out...

protected void btnExportToExcel_Click(object sender, System.EventArgs e)
        {
            try
            {
                string attachment = "attachment; filename=Export.xls";
                Response.ClearContent();
                Response.AddHeader("content-disposition", attachment);
                Response.ContentType = "application/ms-excel";
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);

                // Create a form to contain the grid
                HtmlForm frm = new HtmlForm();
                gvSurvoyDetail.Parent.Controls.Add(frm);
                frm.Attributes["runat"] = "server";
                frm.Controls.Add(gvSurvoyDetail);
                frm.RenderControl(htw);
                Response.Write(sw.ToString());
                Response.End();
            }
            catch (Exception ex)
            {

            }
                        
        }





谢谢



Thanks