解决方案 »

  1.   

    GridView导出Excel并进行格式化示例
    //对单元格字符串进行格式化处理
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:¥#,###.00");
            }
        }//codego.net/tags/1/1/
    //按指定格式定义输出的类型和文件名
     private void Export(string FileType, string FileName)
        {
            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();
        }
    //加载输出信息
     SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
    //显示事件处理
    private void bind()
        {
            SqlDataAdapter myda = new SqlDataAdapter("select top 10 GoodsID as 商品ID,GoodsName as 商品名称,GoodsIntroduce as 商品介绍,GoodsPrice as 商品价格 from tb_GoodsInfo", sqlcon);
            DataSet myds = new DataSet();
            sqlcon.Open();
            myda.Fill(myds);
            sqlcon.Close();
            GridView1.DataSource = myds;
            GridView1.DataBind();
        }
      

  2.   

    html里根本没有列的概念
    excel不过仅仅是能够打开而已
    你想设置列宽自适应,应该导出excel,而不是html修改扩展名
      

  3.   

    NPOI的例子