用你的方法一就可以了,至于有0开头的字符,可以这样处理:比如gdv的第i列是有0开头的,给gdv加RowDataBound方法,protected void gdv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[i].Attributes.Add("class", "text");
    }这样处理后,0开头的数据导入EXCEL也不会丢失了记得抓紧给分~~~

解决方案 »

  1.   

    我以前用的一个方法。看看可是你需要的。。
     protected void Button1_Click(object sender, EventArgs e)
        {
            ExportToExcel("application/ms-excel", "学生信息.xls");    }
        public void ExportToExcel(string FileType, string FileName)
        {
            Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
            Response.ContentType = FileType;
            this.EnableViewState = false;
            StringWriter tw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            GridView1.RenderControl(hw);
            Response.Output.Write(tw.ToString());
            Response.Flush();
            Response.End();    }
        public override void VerifyRenderingInServerForm(Control control)
        {
            //base.VerifyRenderingInServerForm(control);
        }
      

  2.   

    謝謝大家!1樓的方法我之前有試過,但是寫法太死了,我這個函數是公用的,幾百個GRIDVIEW都要調用,我沒辦法一個個去寫吧?有沒更好的辦法呢?
    3樓這個和我的方法一是一樣的呀,解決不了0開始的字串問題,看不出什麼不同,還是我沒看明白?
    我希望是調用公司函數,然後在賦值時來判斷當前是否為數值型,單獨不加引號,可以嗎?
    多謝各位的回復
      

  3.   

    设置range.NumberFormat="@";//设置单元格为文本格式