日期:2014-05-18  浏览次数:20861 次

FastReport直接读取datagridview中显示的数据 打印出来,怎么实现?求代码!
如题: FastReport直接读取datagridview中显示的数据打印出来,怎么实现?现在我有做了个datagridview读出数据的数据了,我现在想要取datagridview的里的某两个字段(如:姓名,编号。。)赋给fastreport我已经设置好的样式


------解决方案--------------------
从gridview直接导出数据到excel
C# code

        Response.Clear();
        Response.Buffer = true;
        Response.Charset = "UTF-8";
        Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.xls");
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        Response.ContentType = "application/ms-excel";
        EnableViewState = false;

        System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("zh-CN", true);
        System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
        System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

//你要打印的结果集
        string StrSQL = "";
        StrSQL = this.getStrSQL();
        DataSet DS = new DataSet();
        DS = Cls_DB_factory._DataSet(StrSQL);

        gview.DataSource = DS.Tables[0];
        gview.DataBind();

        gview.RenderControl(oHtmlTextWriter);

        // this.GridView1.RenderControl(oHtmlTextWriter);
        Response.Write(oStringWriter.ToString());

        Response.End();