Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.UTF7;
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName,     Encoding.UTF8).ToString());
            Response.ContentType = FileType;
            this.EnableViewState = false;
            StringWriter tw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            GridView1.RenderControl(hw);
            Response.Write(tw.ToString());
            Response.End();
导出的execl头标题为粗体(我想要不是粗体的)比如gridview中 数据列值为01 ,02  而到execl中数据变为1 ,2  怎么修正  大家帮帮我

解决方案 »

  1.   

    顶一下,我一般是分一个类,将gridview 一行一行加入到excel 中,先放在网站的临时文件夹下,再输出文件
      

  2.   

    告别excel操作烦恼
      

  3.   

    这个方法导入到Excel中的格式和gridview中的一致的
      

  4.   

    有遇到过LZ这个情况,看到以前报表中的处理方法是在导出Excel的时候把有类似01,02值的列的值都加',因为Excel默认单元格格式会把01转为1认为是数字,加'就不会转换
      

  5.   

    字体问题:UseAccessibleHeader="false"  解决
    gridview中 数据列值为01 ,02  而到execl中数据变为1 ,2 问题  protected void Button2_Click1(object sender, EventArgs e)
        { 
           // Export("application/ms-excel", "兑奖报表.xls");        string style = @"<style> .text { mso-number-format:\@; } </script> "; 
            Response.ClearContent();        Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls");        Response.ContentType = "application/excel";        StringWriter sw = new StringWriter();        HtmlTextWriter htw = new HtmlTextWriter(sw);        GridView1.RenderControl(htw);        Response.Write(style);         Response.Write(sw.ToString());        Response.End();     }
     if (e.Row.RowType == DataControlRowType.DataRow)
            {            e.Row.Cells[2].Attributes.Add("class", "text");
                e.Row.Cells[4].Attributes.Add("class", "text");        } 解决 谢谢给位朋友