如何捕获晶体报告中输入的参数

时间:2013-09-17 14:27:19

标签: vb.net crystal-reports-2008

Crystal Reports vb.net crystalreportviewer导出到文本

我有一个调用水晶报告的.net程序。我想知道你是否可以捕获加载水晶报告时输入的值

enter image description here

我发现我可以在调试时查看参数我只是不确定如何获取值

我希望此图片中的StartValue和EndValue http://i.stack.imgur.com/ThO6j.png

enter image description here

1 个答案:

答案 0 :(得分:0)

我最终做了哪些工作是在水晶报表查看器页面上添加一个按钮..在水晶报表工具栏之后

然后点击我有这个代码

    Private Sub btnExport_Click(sender As System.Object, e As System.EventArgs) Handles btnExport.Click
    Dim rangeval As New ParameterRangeValue
    Dim discrete As New ParameterDiscreteValue
    Dim name As String
    Dim myReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    Dim savefile As New SaveFileDialog
    myReportDocument.Load(Me.CrystalReportViewer1.ReportSource)
    For i = 0 To Me.CrystalReportViewer1.ParameterFieldInfo.Count - 1

        If Me.CrystalReportViewer1.ParameterFieldInfo(i).CurrentValues(0).IsRange = True Then
            name = (CrystalReportViewer1.ParameterFieldInfo(i).Name)
            rangeval = CrystalReportViewer1.ParameterFieldInfo(i).CurrentValues.Item(0)
            'MsgBox(rangeval.StartValue)
            'MsgBox(rangeval.EndValue)
            myReportDocument.SetParameterValue(name, rangeval)
        ElseIf Me.CrystalReportViewer1.ParameterFieldInfo(i).CurrentValues(0).IsRange = False Then
            name = (CrystalReportViewer1.ParameterFieldInfo(i).Name)
            discrete = CrystalReportViewer1.ParameterFieldInfo(i).CurrentValues.Item(0)
            'MsgBox(discrete.Value)
            myReportDocument.SetParameterValue(name, discrete.Value)
        End If
    Next

    savefile.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"

    savefile.Title = ("Save the text file")

    If savefile.ShowDialog = Windows.Forms.DialogResult.OK Then

        myReportDocument.ExportToDisk(ExportFormatType.Text, savefile.FileName)

    End If

End Sub