| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1256 人关注过本帖
标题:水晶报表问题
只看楼主 加入收藏
shinnsora13
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-10-20
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
水晶报表问题
如何通过水晶报表将文本文件转换成rpt格式,再通过水晶报表导出为pdf文件,谢谢大虾指导。
搜索更多相关主题的帖子: 水晶 
2010-11-30 07:48
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:7 
程序代码:
 /// <summary>
         /// 导出报表文件为PDF格式
         /// </summary>
         /// <param name="ReportFile">报表文件名称,调用时请使用Server.MapPath("报表文件.rpt")这样来给这个参数</param>
          /// <param name="ReportDataSource">报表文件所使用的数据源,是一个Dataset</param>
         /// <param name="PDFFileName">你要导成的目标文件名称,注意不要放在wwwroot等目录中,iis会不让你导出的</param>
         /// <returns>bool成功返回true,失败返回false</returns>
         public bool ExportToPDF(string ReportFile,object ReportDataSource,string PDFFileName)
         {
              try
              {
                   ReportDoc.Load(ReportFile);
                   ReportDoc.SetDataSource(ReportDataSource);
                   FileOPS.DiskFileName=PDFFileName;
                   ExOPS=ReportDoc.ExportOptions;
                   ExOPS.DestinationOptions=FileOPS;
                   ExOPS.ExportDestinationType=CrystalDecisions.Shared.ExportDestinationType.DiskFile;
                   ExOPS.ExportFormatType=CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                   ReportDoc.Export();
                   return true;
              }
              catch
              {
                   return false;
              }
         }需要文件一個XSD,RPT

在向子報表中傳參數時,要保持子報表和主表里的參數名稱唯一,即使是傳的是同一值時,在報表中也要用同的不同的參數名稱取值

在傳子報表時只是多傳一數據源
    //主要把數據填入報表中

  public void gfunProcRptForm(DataSet dstData, DataSet SubdstData, string strReportName, string strSubReportName, int intPrintType, string strPrintDate, string strDataDate, string strRemark)
    {

        //要有子報表時在這里多new一個報表文檔

        ReportDocument RptDoc = new ReportDocument();//主報表
        ReportDocument SubRptDoc = new ReportDocument();//子報表
        frmProcRptForm.frmProcRptForm RptProcRptForm = new frmProcRptForm.frmProcRptForm();
        ParameterValues ParaValue = new ParameterValues();
        ParameterDiscreteValue ParaDisValue = new ParameterDiscreteValue();
        WS_TrustProile.WS_TrustProile wsTrustProile = new WS_TrustProile.WS_TrustProile();

        string strsubReportFilePath = "";
        string strSourceReportFilePath = "";
        DataSet dstTrustProile;

        strsubReportFilePath = "";
        dstTrustProile = wsTrustProile.GetTrustProfile();

        if (dstTrustProile.Tables[0].Rows.Count > 0)
        {
            if (!Information.IsDBNull(dstTrustProile.Tables[0].Rows[0]["subReportFilePath"]))
            {
                strsubReportFilePath = dstTrustProile.Tables[0].Rows[0]["subReportFilePath"].ToString();
            }
            if (!Information.IsDBNull(dstTrustProile.Tables[0].Rows[0]["SourceReportFilePath"]))
            {
                strSourceReportFilePath = dstTrustProile.Tables[0].Rows[0]["SourceReportFilePath"].ToString();
            }
            if (!Information.IsDBNull(dstTrustProile.Tables[0].Rows[0]["CMPYName"]))
            {
                sysCMPYName = dstTrustProile.Tables[0].Rows[0]["CMPYName"].ToString();
            }
            comGFunction.CopyFileSTOD("rpt" + strReportName + ".rpt", "2", strSourceReportFilePath, strsubReportFilePath);
        }
        RptDoc.Load(strsubReportFilePath + "rpt" + strReportName + ".rpt");
      
        RptDoc.Database.Tables[0].SetDataSource(dstData.Tables[0]);

        //向主報表中添加子報表
        SubRptDoc = RptDoc.Subreports["rpt" + strSubReportName + ".rpt"];

       //添加子報表數據
        SubRptDoc.SetDataSource(SubdstData.Tables [0]);
        //指定報表參數 - lblCMPYName
        ParaDisValue.Value = sysCMPYName;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblCMPYName"].ApplyCurrentValues(ParaValue);
        //指定報表參數 - lblRemark
        ParaDisValue.Value = strRemark;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblRemark"].ApplyCurrentValues(ParaValue);
        //指定報表參數 - lblSystemUserName
        ParaDisValue.Value = "(" + sysUserID + ")" + sysUserName;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblSystemUserName"].ApplyCurrentValues(ParaValue);
        //指定報表參數 - lblReportNo
        ParaDisValue.Value = strReportName;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblReportNo"].ApplyCurrentValues(ParaValue);
        //指定報表參數 - lblPrintDate
        ParaDisValue.Value = strPrintDate;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblPrintDate"].ApplyCurrentValues(ParaValue);
        //指定報表參數 - lblDataDate
        ParaDisValue.Value = strDataDate;
        ParaValue.Add(ParaDisValue);
        RptDoc.DataDefinition.ParameterFields["lblDataDate"].ApplyCurrentValues(ParaValue);
        RptProcRptForm.CReportViewer.ReportSource = RptDoc;


        if (intPrintType == 1)
        {
            RptDoc.PrintToPrinter(1, true, 0, 0);
        }
        else
        {
            RptProcRptForm.ShowDialog();
        }
    }


水晶报表俺用的不多 相对来说俺更喜欢XtraReport 可以导出EXCEL WORD HTML PDF CSV RPT ....更多的文件类型 实现起来也相当更容易些
收到的鲜花
  • zhoufeng19882010-11-30 09:10 送鲜花  5朵   附言:好文章
  • foktime2010-12-01 08:24 送鲜花  11朵  

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2010-11-30 09:04
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:7 
强烈支持楼上~
我以前做的一个项目,自己用word的动态链接库编的一个导入导出模块,哎哟,累死个人哟。。
2010-11-30 09:10
shinnsora13
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-10-20
收藏
得分:0 
谢谢,很受用。。。
2010-11-30 23:34
江南庞统
Rank: 1
等 级:新手上路
帖 子:1
专家分:7
注 册:2010-12-2
收藏
得分:7 
版主很犀利……
2010-12-02 16:08
快速回复:水晶报表问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020138 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved