解决方案 »

  1.   

    把excel模板建好,这样所有的设置都有了,导出时用程序打开把值给填进去
      

  2.   

    你可以去Excel-Home之类的论坛去问问。
      

  3.   

    数据导出excel并进行格式化
     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();
        }
        private void bind()
        {
            SqlDataAdapter myda = new SqlDataAdapter("select top 10 GoodsID as 商品ID,GoodsName as 商品名称,GoodsIntroduce as 商品介绍,GoodsPrice as 商品价格 from tb_GoodsInfo", sqlcon);//CodeGo.net/
            DataSet myds = new DataSet();
            sqlcon.Open();
            myda.Fill(myds);
            sqlcon.Close();
            GridView1.DataSource = myds;
            GridView1.DataBind();
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
        }
        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");
            }
        }