解决方案 »

  1.   

    你到底是导入还是导出???但是不管导入还是导出 都i建议使用第三方组件,比如 myxls  nopi and so on ...具体的请自行百度
      

  2.   

    在服务器端用OLEDB的方式写入EXCEL,再使用RESPONSE下载到本地,但是下载的EXCEL文件有时候打开就是把当前网页的样式下载下来,而不是数据
      

  3.   

    我做这个的时候没有出现说像你这样不稳定的导出情况,
    但你查看下在导出不好的情况下看是否有Excel进程死在你系统资源当中,这个很容易出现的。
      

  4.   

    嗯 好的,奇怪的是 调试时候不会出现,但是在客户那边出现概率很大,所以就很疑惑,按照道理,服务端上联OFFICE都没安装,不大可能会存在EXCEL的进程存在啊
      

  5.   

    GridView控件数据导出到Excel并格式化
    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");
            }
        }