如果是文本数据使用oledb写入,或者使用三方组件都行。

解决方案 »

  1.   

    将数据导出到Excel并进行格式化希望对您有所帮助
    SqlConnection sqlcon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Export("application/ms-excel", "商品信息表.xls");
        }
        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);
            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");
            }
        }
      

  2.   

    先检查到底是数据来源有问题还是写入EXCEL有问题。盲目怀疑只能是在瞎忙叨。如果数据来源本身就是没有B的信息,你代码再怎么改,也不可能凭空生成B的信息啊